Skip to content

Commit fe43800

Browse files
committed
Fix tests after upgrade @testing-library/react
1 parent c7a523f commit fe43800

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

packages/toolkit/src/query/tests/buildHooks.test.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
actionsReducer,
77
setupApiStore,
88
useRenderCounter,
9+
waitForFakeTimer,
910
waitMs,
1011
withProvider,
1112
} from '@internal/tests/utils/helpers'
@@ -46,7 +47,7 @@ interface Item {
4647

4748
const api = createApi({
4849
baseQuery: async (arg: any) => {
49-
await waitMs(150)
50+
await waitForFakeTimer(10)
5051
if (arg?.body && 'amount' in arg.body) {
5152
amount += 1
5253
}
@@ -942,15 +943,15 @@ describe('hooks tests', () => {
942943
// Allow at least three state effects to hit.
943944
// Trying to see if any [true, false, true] occurs.
944945
await act(async () => {
945-
await waitMs(1)
946+
await waitForFakeTimer(10)
946947
})
947948

948949
await act(async () => {
949-
await waitMs(1)
950+
await waitForFakeTimer(10)
950951
})
951952

952953
await act(async () => {
953-
await waitMs(1)
954+
await waitForFakeTimer(10)
954955
})
955956

956957
// Find if at any time the isLoading state has reverted
@@ -1669,7 +1670,8 @@ describe('hooks tests', () => {
16691670
expect(screen.getByTestId('isFetching').textContent).toBe('false'),
16701671
)
16711672

1672-
userEvent.hover(screen.getByTestId('highPriority'))
1673+
await userEvent.hover(screen.getByTestId('highPriority'))
1674+
16731675
expect(
16741676
api.endpoints.getUser.select(USER_ID)(storeRef.store.getState() as any),
16751677
).toEqual({
@@ -1806,7 +1808,7 @@ describe('hooks tests', () => {
18061808
await waitMs(400)
18071809

18081810
// This should run the query being that we're past the threshold
1809-
userEvent.hover(screen.getByTestId('lowPriority'))
1811+
await userEvent.hover(screen.getByTestId('lowPriority'))
18101812
expect(
18111813
api.endpoints.getUser.select(USER_ID)(storeRef.store.getState() as any),
18121814
).toEqual({
@@ -1906,7 +1908,7 @@ describe('hooks tests', () => {
19061908

19071909
render(<User />, { wrapper: storeRef.wrapper })
19081910

1909-
userEvent.hover(screen.getByTestId('lowPriority'))
1911+
await userEvent.hover(screen.getByTestId('lowPriority'))
19101912

19111913
expect(
19121914
api.endpoints.getUser.select(USER_ID)(storeRef.store.getState() as any),
@@ -2798,6 +2800,11 @@ describe('skip behavior', () => {
27982800
await act(async () => {
27992801
rerender([1])
28002802
})
2803+
2804+
await act(async () => {
2805+
await waitForFakeTimer(10)
2806+
})
2807+
28012808
expect(result.current).toMatchObject({ status: QueryStatus.fulfilled })
28022809
await waitMs(1)
28032810
expect(getSubscriptionCount('getUser(1)')).toBe(1)
@@ -2834,6 +2841,11 @@ describe('skip behavior', () => {
28342841
await act(async () => {
28352842
rerender([1])
28362843
})
2844+
2845+
await act(async () => {
2846+
await waitForFakeTimer(10)
2847+
})
2848+
28372849
expect(result.current).toMatchObject({ status: QueryStatus.fulfilled })
28382850
await waitMs(1)
28392851
expect(getSubscriptionCount('getUser(1)')).toBe(1)
@@ -2862,7 +2874,7 @@ describe('skip behavior', () => {
28622874
)
28632875

28642876
await act(async () => {
2865-
await waitMs(1)
2877+
await waitForFakeTimer(10)
28662878
})
28672879

28682880
// Normal fulfilled result, with both `data` and `currentData`

packages/toolkit/src/query/tests/cleanup.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function UsingAB() {
4343
}
4444

4545
beforeAll(() => {
46-
vi.useFakeTimers()
46+
vi.useFakeTimers({ shouldAdvanceTime: true })
4747
})
4848

4949
test('data stays in store when component stays rendered', async () => {

0 commit comments

Comments
 (0)