Repository: tannerlinsley/react-query
File: packages/query-core/src/__tests__/infiniteQueryBehavior.test.tsx (TypeScript)

Code before:
    )

    unsubscribe()
  })

  test('InfiniteQueryBehavior should handle null page parameters correctly', async () => {
    const key = queryKey()

    const queryFnSpy = vi.fn().mockImplementation(({ pageParam }) => {
      return pageParam
    })

    const observer = new InfiniteQueryObserver<number>(queryClient, {
      queryKey: key,
      queryFn: queryFnSpy,
      getNextPageParam: (lastPage) => (lastPage === 1 ? null : lastPage + 1),
      initialPageParam: 1,
    })

    let observerResult:
      | InfiniteQueryObserverResult<unknown, unknown>
      | undefined

    const unsubscribe = observer.subscribe((result) => {
      observerResult = result
    })

    await vi.waitFor(() =>
      expect(observerResult).toMatchObject({
        isFetching: false,
        data: { pages: [1], pageParams: [1] },
      }),
    )

    await observer.fetchNextPage()

    expect(observerResult).toMatchObject({
      isFetching: false,
      data: { pages: [1], pageParams: [1] },
    })

    unsubscribe()
  })

  test('InfiniteQueryBehavior should use persister when provided', async () => {
    const key = queryKey()

    const queryFnSpy = vi.fn().mockImplementation(({ pageParam }) => {
      return pageParam
    })


Review comment (suggestion):
In my opinion, this test don't need mocked function

```suggestion
    const key = queryKey()

    const observer = new InfiniteQueryObserver(queryClient, {
      queryKey: key,
      queryFn: ({ pageParam }) => sleep(0).then(() => pageParam),
      getNextPageParam: (lastPage) => (lastPage === 1 ? null : lastPage + 1),
      initialPageParam: 1,
    })

    let observerResult:
      | InfiniteQueryObserverResult<InfiniteData<number, unknown>, Error>
      | undefined

    const unsubscribe = observer.subscribe((result) => {
      observerResult = result
    })
```

Code after:
    )

    unsubscribe()
  })

  test('InfiniteQueryBehavior should not fetch next page when getNextPageParam returns null', async () => {
    const key = queryKey()

    const observer = new InfiniteQueryObserver(queryClient, {
      queryKey: key,
      queryFn: ({ pageParam }) => sleep(0).then(() => pageParam),
      getNextPageParam: (lastPage) => (lastPage === 1 ? null : lastPage + 1),
      initialPageParam: 1,
    })

    let observerResult:
      | InfiniteQueryObserverResult<InfiniteData<number, unknown>, Error>
      | undefined

    const unsubscribe = observer.subscribe((result) => {
      observerResult = result
    })

    await vi.waitFor(() =>
      expect(observerResult).toMatchObject({
        isFetching: false,
        data: { pages: [1], pageParams: [1] },
      }),
    )

    await observer.fetchNextPage()

    expect(observerResult).toMatchObject({
      isFetching: false,
      data: { pages: [1], pageParams: [1] },
    })

    unsubscribe()
  })

  test('InfiniteQueryBehavior should use persister when provided', async () => {
    const key = queryKey()

    const persisterSpy = vi.fn().mockImplementation(async (fn) => {
      return await fn()
    })

    const observer = new InfiniteQueryObserver(queryClient, {
      queryKey: key,
      queryFn: ({ pageParam }) => sleep(0).then(() => pageParam),
      getNextPageParam: (lastPage) => lastPage + 1,