Skip to content

Commit

Permalink
reset
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT committed Dec 13, 2024
1 parent 46d145c commit 201169a
Showing 1 changed file with 14 additions and 41 deletions.
55 changes: 14 additions & 41 deletions packages/react-query/src/__tests__/useSuspenseQuery.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { describe, expect, it, vi } from 'vitest'
import { fireEvent, waitFor } from '@testing-library/react'
import * as React from 'react'
import { ErrorBoundary } from 'react-error-boundary'
import { describe, expect, it, vi } from 'vitest'
import type {
InfiniteData,
UseSuspenseInfiniteQueryResult,
UseSuspenseQueryResult,
} from '..'
import {
QueryCache,
QueryErrorResetBoundary,
Expand All @@ -15,13 +10,12 @@ import {
useSuspenseInfiniteQuery,
useSuspenseQuery,
} from '..'
import {
arrayPick,
createQueryClient,
queryKey,
renderWithClient,
sleep,
} from './utils'
import { createQueryClient, queryKey, renderWithClient, sleep } from './utils'
import type {
InfiniteData,
UseSuspenseInfiniteQueryResult,
UseSuspenseQueryResult,
} from '..'

describe('useSuspenseQuery', () => {
const queryCache = new QueryCache()
Expand Down Expand Up @@ -66,34 +60,14 @@ describe('useSuspenseQuery', () => {
)

await waitFor(() => rendered.getByText('data: 1'))
expect(states.length).toBe(1)

fireEvent.click(rendered.getByLabelText('toggle'))

await waitFor(() => rendered.getByText('data: 2'))

expect(renders).toBe(8)

// The suspense is triggered after setting the setting the new result, which is why this is 3 instead of 2
expect(states.length).toBe(3)

const pickedStates = arrayPick(states, ['data', 'status'])
expect(pickedStates).toMatchInlineSnapshot(`
[
{
"data": 1,
"status": "success",
},
{
"data": 1,
"status": "success",
},
{
"data": 2,
"status": "success",
},
]
`)
expect(renders).toBe(6)
expect(states.length).toBe(2)
expect(states[0]).toMatchObject({ data: 1, status: 'success' })
expect(states[1]).toMatchObject({ data: 2, status: 'success' })
})

it('should return the correct states for a successful infinite query', async () => {
Expand Down Expand Up @@ -139,9 +113,8 @@ describe('useSuspenseQuery', () => {
fireEvent.click(rendered.getByText('next'))
await waitFor(() => rendered.getByText('data: 2'))

// The suspense is triggered after setting the setting the new result, which is why this is 3 instead of 2
expect(states.length).toBe(3)
expect(states[2]).toMatchObject({
expect(states.length).toBe(2)
expect(states[1]).toMatchObject({
data: { pages: [2], pageParams: [1] },
status: 'success',
})
Expand Down Expand Up @@ -930,4 +903,4 @@ describe('useSuspenseQuery', () => {
)
consoleErrorSpy.mockRestore()
})
})
})

0 comments on commit 201169a

Please sign in to comment.