Skip to content

Commit b76a4ea

Browse files
committed
avoid use snapshot
1 parent ba01a07 commit b76a4ea

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

src/tests/suspense.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { render, waitForElement, fireEvent, cleanup } from '@testing-library/react'
1+
import {
2+
render,
3+
waitForElement,
4+
fireEvent,
5+
cleanup,
6+
} from '@testing-library/react'
27
import * as React from 'react'
38

49
import { useQuery, ReactQueryCacheProvider, queryCache } from '../index'

src/tests/useQuery.test.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { render, act, waitForElement, fireEvent, cleanup, waitForDomChange } from '@testing-library/react'
1+
import {
2+
render,
3+
act,
4+
waitForElement,
5+
fireEvent,
6+
cleanup,
7+
waitForDomChange,
8+
} from '@testing-library/react'
29
import { ErrorBoundary } from 'react-error-boundary'
310
import * as React from 'react'
411

@@ -1013,56 +1020,55 @@ describe('useQuery', () => {
10131020
)
10141021
}
10151022
const { container } = render(<Page />)
1016-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: "`)
1017-
1023+
expect(container.firstChild.textContent).toEqual('count: ')
10181024
await waitForDomChange({ container }) // mount
1019-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 0"`)
1025+
expect(container.firstChild.textContent).toEqual('count: 0')
10201026
await act(() => {
10211027
return new Promise(res => setTimeout(res, 210))
10221028
})
1023-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 1"`)
1029+
expect(container.firstChild.textContent).toEqual('count: 1')
10241030
await act(() => {
10251031
return new Promise(res => setTimeout(res, 50))
10261032
})
1027-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 1"`)
1033+
expect(container.firstChild.textContent).toEqual('count: 1')
10281034
await act(() => {
10291035
return new Promise(res => setTimeout(res, 150))
10301036
})
1031-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 2"`)
1037+
expect(container.firstChild.textContent).toEqual('count: 2')
10321038
await act(() => {
10331039
fireEvent.click(container.firstElementChild)
10341040
// it will clear 200ms timer and setup a new 300ms timer
10351041
return new Promise(res => setTimeout(res, 200))
10361042
})
1037-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 2"`)
1043+
expect(container.firstChild.textContent).toEqual('count: 2')
10381044
await act(() => {
10391045
return new Promise(res => setTimeout(res, 110))
10401046
})
1041-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 3"`)
1047+
expect(container.firstChild.textContent).toEqual('count: 3')
10421048
await act(() => {
10431049
// wait for new 300ms timer
10441050
return new Promise(res => setTimeout(res, 310))
10451051
})
1046-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 4"`)
1052+
expect(container.firstChild.textContent).toEqual('count: 4')
10471053
await act(() => {
10481054
fireEvent.click(container.firstElementChild)
10491055
// it will clear 300ms timer and setup a new 400ms timer
10501056
return new Promise(res => setTimeout(res, 300))
10511057
})
1052-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 4"`)
1058+
expect(container.firstChild.textContent).toEqual('count: 4')
10531059
await act(() => {
10541060
return new Promise(res => setTimeout(res, 110))
10551061
})
1056-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 5"`)
1062+
expect(container.firstChild.textContent).toEqual('count: 5')
10571063
await act(() => {
10581064
fireEvent.click(container.firstElementChild)
10591065
// it will clear 400ms timer and stop
10601066
return new Promise(res => setTimeout(res, 110))
10611067
})
1062-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 5"`)
1068+
expect(container.firstChild.textContent).toEqual('count: 5')
10631069
await act(() => {
10641070
return new Promise(res => setTimeout(res, 110))
10651071
})
1066-
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 5"`)
1072+
expect(container.firstChild.textContent).toEqual('count: 5')
10671073
})
10681074
})

0 commit comments

Comments
 (0)