|
6 | 6 | actionsReducer, |
7 | 7 | setupApiStore, |
8 | 8 | useRenderCounter, |
| 9 | + waitForFakeTimer, |
9 | 10 | waitMs, |
10 | 11 | withProvider, |
11 | 12 | } from '@internal/tests/utils/helpers' |
@@ -47,7 +48,7 @@ interface Item { |
47 | 48 |
|
48 | 49 | const api = createApi({ |
49 | 50 | baseQuery: async (arg: any) => { |
50 | | - await waitMs(150) |
| 51 | + await waitForFakeTimer(150) |
51 | 52 | if (arg?.body && 'amount' in arg.body) { |
52 | 53 | amount += 1 |
53 | 54 | } |
@@ -465,7 +466,6 @@ describe('hooks tests', () => { |
465 | 466 | <div> |
466 | 467 | <button |
467 | 468 | onClick={() => { |
468 | | - console.log('Refetching') |
469 | 469 | refetch() |
470 | 470 | }} |
471 | 471 | > |
@@ -915,7 +915,7 @@ describe('hooks tests', () => { |
915 | 915 | resPromise = refetch() |
916 | 916 | }) |
917 | 917 | expect(resPromise).toBeInstanceOf(Promise) |
918 | | - const res = await resPromise |
| 918 | + const res = await act(() => resPromise) |
919 | 919 | expect(res.data!.amount).toBeGreaterThan(originalAmount) |
920 | 920 | }) |
921 | 921 |
|
@@ -1095,15 +1095,15 @@ describe('hooks tests', () => { |
1095 | 1095 | // Allow at least three state effects to hit. |
1096 | 1096 | // Trying to see if any [true, false, true] occurs. |
1097 | 1097 | await act(async () => { |
1098 | | - await waitMs(1) |
| 1098 | + await waitForFakeTimer(150) |
1099 | 1099 | }) |
1100 | 1100 |
|
1101 | 1101 | await act(async () => { |
1102 | | - await waitMs(1) |
| 1102 | + await waitForFakeTimer(150) |
1103 | 1103 | }) |
1104 | 1104 |
|
1105 | 1105 | await act(async () => { |
1106 | | - await waitMs(1) |
| 1106 | + await waitForFakeTimer(150) |
1107 | 1107 | }) |
1108 | 1108 |
|
1109 | 1109 | // Find if at any time the isLoading state has reverted |
@@ -1864,7 +1864,8 @@ describe('hooks tests', () => { |
1864 | 1864 | expect(screen.getByTestId('isFetching').textContent).toBe('false'), |
1865 | 1865 | ) |
1866 | 1866 |
|
1867 | | - userEvent.hover(screen.getByTestId('highPriority')) |
| 1867 | + await userEvent.hover(screen.getByTestId('highPriority')) |
| 1868 | + |
1868 | 1869 | expect( |
1869 | 1870 | api.endpoints.getUser.select(USER_ID)(storeRef.store.getState() as any), |
1870 | 1871 | ).toEqual({ |
@@ -2001,7 +2002,7 @@ describe('hooks tests', () => { |
2001 | 2002 | await waitMs(400) |
2002 | 2003 |
|
2003 | 2004 | // This should run the query being that we're past the threshold |
2004 | | - userEvent.hover(screen.getByTestId('lowPriority')) |
| 2005 | + await userEvent.hover(screen.getByTestId('lowPriority')) |
2005 | 2006 | expect( |
2006 | 2007 | api.endpoints.getUser.select(USER_ID)(storeRef.store.getState() as any), |
2007 | 2008 | ).toEqual({ |
@@ -2101,7 +2102,7 @@ describe('hooks tests', () => { |
2101 | 2102 |
|
2102 | 2103 | render(<User />, { wrapper: storeRef.wrapper }) |
2103 | 2104 |
|
2104 | | - userEvent.hover(screen.getByTestId('lowPriority')) |
| 2105 | + await userEvent.hover(screen.getByTestId('lowPriority')) |
2105 | 2106 |
|
2106 | 2107 | expect( |
2107 | 2108 | api.endpoints.getUser.select(USER_ID)(storeRef.store.getState() as any), |
@@ -2993,6 +2994,11 @@ describe('skip behavior', () => { |
2993 | 2994 | await act(async () => { |
2994 | 2995 | rerender([1]) |
2995 | 2996 | }) |
| 2997 | + |
| 2998 | + await act(async () => { |
| 2999 | + await waitForFakeTimer(150) |
| 3000 | + }) |
| 3001 | + |
2996 | 3002 | expect(result.current).toMatchObject({ status: QueryStatus.fulfilled }) |
2997 | 3003 | await waitMs(1) |
2998 | 3004 | expect(getSubscriptionCount('getUser(1)')).toBe(1) |
@@ -3030,6 +3036,11 @@ describe('skip behavior', () => { |
3030 | 3036 | await act(async () => { |
3031 | 3037 | rerender([1]) |
3032 | 3038 | }) |
| 3039 | + |
| 3040 | + await act(async () => { |
| 3041 | + await waitForFakeTimer(150) |
| 3042 | + }) |
| 3043 | + |
3033 | 3044 | expect(result.current).toMatchObject({ status: QueryStatus.fulfilled }) |
3034 | 3045 | await waitMs(1) |
3035 | 3046 | expect(getSubscriptionCount('getUser(1)')).toBe(1) |
@@ -3059,7 +3070,7 @@ describe('skip behavior', () => { |
3059 | 3070 | ) |
3060 | 3071 |
|
3061 | 3072 | await act(async () => { |
3062 | | - await waitMs(1) |
| 3073 | + await waitForFakeTimer(150) |
3063 | 3074 | }) |
3064 | 3075 |
|
3065 | 3076 | // Normal fulfilled result, with both `data` and `currentData` |
|
0 commit comments