|
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' |
2 | 9 | import { ErrorBoundary } from 'react-error-boundary' |
3 | 10 | import * as React from 'react' |
4 | 11 |
|
@@ -1013,56 +1020,55 @@ describe('useQuery', () => { |
1013 | 1020 | ) |
1014 | 1021 | } |
1015 | 1022 | const { container } = render(<Page />) |
1016 | | - expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: "`) |
1017 | | - |
| 1023 | + expect(container.firstChild.textContent).toEqual('count: ') |
1018 | 1024 | await waitForDomChange({ container }) // mount |
1019 | | - expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 0"`) |
| 1025 | + expect(container.firstChild.textContent).toEqual('count: 0') |
1020 | 1026 | await act(() => { |
1021 | 1027 | return new Promise(res => setTimeout(res, 210)) |
1022 | 1028 | }) |
1023 | | - expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 1"`) |
| 1029 | + expect(container.firstChild.textContent).toEqual('count: 1') |
1024 | 1030 | await act(() => { |
1025 | 1031 | return new Promise(res => setTimeout(res, 50)) |
1026 | 1032 | }) |
1027 | | - expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 1"`) |
| 1033 | + expect(container.firstChild.textContent).toEqual('count: 1') |
1028 | 1034 | await act(() => { |
1029 | 1035 | return new Promise(res => setTimeout(res, 150)) |
1030 | 1036 | }) |
1031 | | - expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 2"`) |
| 1037 | + expect(container.firstChild.textContent).toEqual('count: 2') |
1032 | 1038 | await act(() => { |
1033 | 1039 | fireEvent.click(container.firstElementChild) |
1034 | 1040 | // it will clear 200ms timer and setup a new 300ms timer |
1035 | 1041 | return new Promise(res => setTimeout(res, 200)) |
1036 | 1042 | }) |
1037 | | - expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 2"`) |
| 1043 | + expect(container.firstChild.textContent).toEqual('count: 2') |
1038 | 1044 | await act(() => { |
1039 | 1045 | return new Promise(res => setTimeout(res, 110)) |
1040 | 1046 | }) |
1041 | | - expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 3"`) |
| 1047 | + expect(container.firstChild.textContent).toEqual('count: 3') |
1042 | 1048 | await act(() => { |
1043 | 1049 | // wait for new 300ms timer |
1044 | 1050 | return new Promise(res => setTimeout(res, 310)) |
1045 | 1051 | }) |
1046 | | - expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 4"`) |
| 1052 | + expect(container.firstChild.textContent).toEqual('count: 4') |
1047 | 1053 | await act(() => { |
1048 | 1054 | fireEvent.click(container.firstElementChild) |
1049 | 1055 | // it will clear 300ms timer and setup a new 400ms timer |
1050 | 1056 | return new Promise(res => setTimeout(res, 300)) |
1051 | 1057 | }) |
1052 | | - expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 4"`) |
| 1058 | + expect(container.firstChild.textContent).toEqual('count: 4') |
1053 | 1059 | await act(() => { |
1054 | 1060 | return new Promise(res => setTimeout(res, 110)) |
1055 | 1061 | }) |
1056 | | - expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 5"`) |
| 1062 | + expect(container.firstChild.textContent).toEqual('count: 5') |
1057 | 1063 | await act(() => { |
1058 | 1064 | fireEvent.click(container.firstElementChild) |
1059 | 1065 | // it will clear 400ms timer and stop |
1060 | 1066 | return new Promise(res => setTimeout(res, 110)) |
1061 | 1067 | }) |
1062 | | - expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 5"`) |
| 1068 | + expect(container.firstChild.textContent).toEqual('count: 5') |
1063 | 1069 | await act(() => { |
1064 | 1070 | return new Promise(res => setTimeout(res, 110)) |
1065 | 1071 | }) |
1066 | | - expect(container.firstChild.textContent).toMatchInlineSnapshot(`"count: 5"`) |
| 1072 | + expect(container.firstChild.textContent).toEqual('count: 5') |
1067 | 1073 | }) |
1068 | 1074 | }) |
0 commit comments