Repository: nuxt/nuxt
File: test/nuxt/composables.test.ts (TypeScript)

Code before:
    }
  })

  it('should timeout', async () => {
    const { status, error } = await useFetch(
      // @ts-expect-error should resolve to a string
      () => new Promise(resolve => setTimeout(resolve, 5000)),
      { timeout: 1 },
    )
    await new Promise(resolve => setTimeout(resolve, 2))
    expect(status.value).toBe('error')
    expect(error.value).toMatchInlineSnapshot(`[Error: [GET] "[object Promise]": <no response> Failed to parse URL from [object Promise]]`)
  })

  it.runIf(process.env.PROJECT === 'nuxt-legacy')('should fetch if immediate is false and only the key changes with `experimental.alwaysRunFetchOnKeyChange`', async () => {
    const key = shallowRef('a')
    const { status } = useFetch('/api/test', { key, immediate: false })

    expect.soft(status.value).toBe('idle')

    key.value += 'a'
    await nextTick()
    expect.soft(status.value).toBe('pending')
  })

  it.skipIf(process.env.NUXT_LEGACY !== '1')('should handle parallel execute with `immediate: false`', async () => {
    const query = reactive({ q: 1 })
    const { execute, status } = useFetch(
      '/api/test',
      {
        query,
        immediate: false,
      },
    )
    watch(query, () => execute(), { once: true })

    expect.soft(status.value).toBe('idle')
    query.q++
    query.q++

    await nextTick()
    query.q++

    expect.soft(status.value).toBe('pending')
    await vi.waitFor(() => {
      expect(status.value).toBe('success')
    })
    query.q++
    expect.soft(status.value).toBe('pending')
  })
})

Review comment (suggestion):
I think this is not running at all at the moment. I updated the env variable before merging the other PR:

```suggestion
  it.runIf(process.env.PROJECT === 'nuxt-legacy')('should handle parallel execute with `immediate: false`', async () => {
```

Code after:
    }
  })

  it('should timeout', async () => {
    const { status, error } = await useFetch(
      // @ts-expect-error should resolve to a string
      () => new Promise(resolve => setTimeout(resolve, 5000)),
      { timeout: 1 },
    )
    await new Promise(resolve => setTimeout(resolve, 2))
    expect(status.value).toBe('error')
    expect(error.value).toMatchInlineSnapshot(`[Error: [GET] "[object Promise]": <no response> Failed to parse URL from [object Promise]]`)
  })

  it.runIf(process.env.PROJECT === 'nuxt-legacy')('should fetch if immediate is false and only the key changes with `experimental.alwaysRunFetchOnKeyChange`', async () => {
    const key = shallowRef('a')
    const { status } = useFetch('/api/test', { key, immediate: false })

    expect.soft(status.value).toBe('idle')

    key.value += 'a'
    await nextTick()
    expect.soft(status.value).toBe('pending')
  })

  it('should handle parallel execute with `immediate: false`', async () => {
    const query = reactive({ q: 1 })
    const { execute, status } = useFetch(
      '/api/test',
      {
        query,
        immediate: false,
      },
    )
    watch(query, () => execute(), { once: true })

    expect.soft(status.value).toBe('idle')
    query.q++
    query.q++

    await nextTick()
    query.q++

    expect.soft(status.value).toBe('pending')
    await vi.waitFor(() => {
      expect(status.value).toBe('success')
    })
    query.q++
    expect.soft(status.value).toBe('pending')
  })
})