Repository: tanstack/query
File: packages/query-core/src/__tests__/queryClient.test.tsx (TypeScript)

Code before:
        { predicate: (query) => query === query1 },
        (old) => old! + 5,
      )

      expect(result).toEqual([[['key', 1], 6]])
      expect(queryClient.getQueryData(['key', 1])).toBe(6)
      expect(queryClient.getQueryData(['key', 2])).toBe(2)
    })

    test('should not update non existing queries', () => {
      const result = queryClient.setQueriesData<string>(
        { queryKey: ['key'] },
        'data',
      )

      expect(result).toEqual([])
      expect(queryClient.getQueryData(['key'])).toBe(undefined)
    })
  })

  describe('isFetching', () => {
    test('should return length of fetching queries', async () => {
      const key1 = queryKey()
      const key2 = queryKey()

      expect(queryClient.isFetching()).toBe(0)
      queryClient.prefetchQuery({
        queryKey: key1,
        queryFn: () => sleep(30).then(() => 'data'),
      })
      expect(queryClient.isFetching()).toBe(1)
      queryClient.prefetchQuery({
        queryKey: key2,
        queryFn: () => sleep(5).then(() => 'data'),
      })
      expect(queryClient.isFetching()).toBe(2)
      await waitFor(() => expect(queryClient.isFetching()).toEqual(1))
      await waitFor(() => expect(queryClient.isFetching()).toEqual(0))
    })
  })

  describe('getQueryData', () => {
    test('should return the query data if the query is found', () => {
      const key = queryKey()
      queryClient.setQueryData([key, 'id'], 'bar')
      expect(queryClient.getQueryData([key, 'id'])).toBe('bar')
    })

    test('should return undefined if the query is not found', () => {
      const key = queryKey()
      expect(queryClient.getQueryData(key)).toBeUndefined()

Review comment (suggestion):
```suggestion
        queryFn: () => sleep(25).then(() => 'data'),
```

Code after:
      expect(queryClient.getQueryData(['key', 1])).toBe(6)
      expect(queryClient.getQueryData(['key', 2])).toBe(2)
    })

    test('should not update non existing queries', () => {
      const result = queryClient.setQueriesData<string>(
        { queryKey: ['key'] },
        'data',
      )

      expect(result).toEqual([])
      expect(queryClient.getQueryData(['key'])).toBe(undefined)
    })
  })

  describe('isFetching', () => {
    test('should return length of fetching queries', async () => {
      expect(queryClient.isFetching()).toBe(0)
      queryClient.prefetchQuery({
        queryKey: queryKey(),
        queryFn: () => sleep(10).then(() => 'data'),
      })
      expect(queryClient.isFetching()).toBe(1)
      queryClient.prefetchQuery({
        queryKey: queryKey(),
        queryFn: () => sleep(5).then(() => 'data'),
      })
      expect(queryClient.isFetching()).toBe(2)
      await vi.advanceTimersByTimeAsync(5)
      expect(queryClient.isFetching()).toEqual(1)
      await vi.advanceTimersByTimeAsync(5)
      expect(queryClient.isFetching()).toEqual(0)
    })
  })

  describe('getQueryData', () => {
    test('should return the query data if the query is found', () => {
      const key = queryKey()
      queryClient.setQueryData([key, 'id'], 'bar')
      expect(queryClient.getQueryData([key, 'id'])).toBe('bar')
    })

    test('should return undefined if the query is not found', () => {
      const key = queryKey()
      expect(queryClient.getQueryData(key)).toBeUndefined()
    })

    test('should match exact by default', () => {
      const key = queryKey()
      queryClient.setQueryData([key, 'id'], 'bar')
      expect(queryClient.getQueryData([key])).toBeUndefined()