From a531f50e7dff972ed4bf911478f064353ca1c46b Mon Sep 17 00:00:00 2001 From: isqua Date: Fri, 1 Nov 2024 19:23:25 +0100 Subject: [PATCH 1/7] Upgrade @testing-library/react from 13.3.0 to 16.0.1 --- examples/query/react/basic/package.json | 3 +- .../query/react/kitchen-sink/package.json | 3 +- packages/toolkit/package.json | 5 +- yarn.lock | 96 ++++++++++++------- 4 files changed, 70 insertions(+), 37 deletions(-) diff --git a/examples/query/react/basic/package.json b/examples/query/react/basic/package.json index 709c27b6c8..fc44afac89 100644 --- a/examples/query/react/basic/package.json +++ b/examples/query/react/basic/package.json @@ -13,7 +13,8 @@ "react-scripts": "5.0.1" }, "devDependencies": { - "@testing-library/react": "^13.3.0", + "@testing-library/dom": "^10.4.0", + "@testing-library/react": "^16.0.1", "@types/jest": "^26.0.23", "@types/react": "^18.0.5", "@types/react-dom": "^18.0.5", diff --git a/examples/query/react/kitchen-sink/package.json b/examples/query/react/kitchen-sink/package.json index 2e1675c6fc..c0e5794127 100644 --- a/examples/query/react/kitchen-sink/package.json +++ b/examples/query/react/kitchen-sink/package.json @@ -15,8 +15,9 @@ "react-scripts": "5.0.1" }, "devDependencies": { + "@testing-library/dom": "^10.4.0", "@testing-library/jest-dom": "^5.11.5", - "@testing-library/react": "^13.3.0", + "@testing-library/react": "^16.0.1", "@types/jest": "^26.0.23", "@types/node": "^14.14.6", "@types/react": "^18.0.5", diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index e3c3c8b6f3..dee00cc37a 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -56,8 +56,9 @@ "@phryneas/ts-version": "^1.0.2", "@size-limit/file": "^11.0.1", "@size-limit/webpack": "^11.0.1", - "@testing-library/react": "^13.3.0", - "@testing-library/user-event": "^13.1.5", + "@testing-library/dom": "^10.4.0", + "@testing-library/react": "^16.0.1", + "@testing-library/user-event": "^14.5.2", "@types/babel__core": "^7.20.5", "@types/babel__helper-module-imports": "^7.18.3", "@types/json-stringify-safe": "^5.0.0", diff --git a/yarn.lock b/yarn.lock index e88f6db1e1..b503e74683 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4618,7 +4618,8 @@ __metadata: resolution: "@examples-query-react/basic@workspace:examples/query/react/basic" dependencies: "@reduxjs/toolkit": "npm:^1.6.0-rc.1" - "@testing-library/react": "npm:^13.3.0" + "@testing-library/dom": "npm:^10.4.0" + "@testing-library/react": "npm:^16.0.1" "@types/jest": "npm:^26.0.23" "@types/react": "npm:^18.0.5" "@types/react-dom": "npm:^18.0.5" @@ -4735,8 +4736,9 @@ __metadata: resolution: "@examples-query-react/kitchen-sink@workspace:examples/query/react/kitchen-sink" dependencies: "@reduxjs/toolkit": "npm:1.8.1" + "@testing-library/dom": "npm:^10.4.0" "@testing-library/jest-dom": "npm:^5.11.5" - "@testing-library/react": "npm:^13.3.0" + "@testing-library/react": "npm:^16.0.1" "@types/jest": "npm:^26.0.23" "@types/node": "npm:^14.14.6" "@types/react": "npm:^18.0.5" @@ -6676,8 +6678,9 @@ __metadata: "@phryneas/ts-version": "npm:^1.0.2" "@size-limit/file": "npm:^11.0.1" "@size-limit/webpack": "npm:^11.0.1" - "@testing-library/react": "npm:^13.3.0" - "@testing-library/user-event": "npm:^13.1.5" + "@testing-library/dom": "npm:^10.4.0" + "@testing-library/react": "npm:^16.0.1" + "@testing-library/user-event": "npm:^14.5.2" "@types/babel__core": "npm:^7.20.5" "@types/babel__helper-module-imports": "npm:^7.18.3" "@types/json-stringify-safe": "npm:^5.0.0" @@ -7512,19 +7515,19 @@ __metadata: languageName: node linkType: hard -"@testing-library/dom@npm:^8.5.0": - version: 8.13.0 - resolution: "@testing-library/dom@npm:8.13.0" +"@testing-library/dom@npm:^10.4.0": + version: 10.4.0 + resolution: "@testing-library/dom@npm:10.4.0" dependencies: "@babel/code-frame": "npm:^7.10.4" "@babel/runtime": "npm:^7.12.5" - "@types/aria-query": "npm:^4.2.0" - aria-query: "npm:^5.0.0" + "@types/aria-query": "npm:^5.0.1" + aria-query: "npm:5.3.0" chalk: "npm:^4.1.0" dom-accessibility-api: "npm:^0.5.9" - lz-string: "npm:^1.4.4" + lz-string: "npm:^1.5.0" pretty-format: "npm:^27.0.2" - checksum: 10/e91bf4261b8f8c191f62fd44548d39fe8dab7d12f9ecbfdec8cc0060b4030e837f4626b0256a795cc91db9ba20fc9b97005247d951b21449751af26dbb8c7191 + checksum: 10/05825ee9a15b88cbdae12c137db7111c34069ed3c7a1bd03b6696cb1b37b29f6f2d2de581ebf03033e7df1ab7ebf08399310293f440a4845d95c02c0a9ecc899 languageName: node linkType: hard @@ -7545,28 +7548,32 @@ __metadata: languageName: node linkType: hard -"@testing-library/react@npm:^13.3.0": - version: 13.3.0 - resolution: "@testing-library/react@npm:13.3.0" +"@testing-library/react@npm:^16.0.1": + version: 16.0.1 + resolution: "@testing-library/react@npm:16.0.1" dependencies: "@babel/runtime": "npm:^7.12.5" - "@testing-library/dom": "npm:^8.5.0" - "@types/react-dom": "npm:^18.0.0" peerDependencies: + "@testing-library/dom": ^10.0.0 + "@types/react": ^18.0.0 + "@types/react-dom": ^18.0.0 react: ^18.0.0 react-dom: ^18.0.0 - checksum: 10/f72ff8e5f5268788ea2249bc0d8dceeca91f9fbad23fd718403e7c9518ea7b9f0053d96db7c3b2d20fc51b487b37ac6c5d55e7f732cadf786c8fa763ce1efec6 + peerDependenciesMeta: + "@types/react": + optional: true + "@types/react-dom": + optional: true + checksum: 10/904b48881cf5bd208e25899e168f5c99c78ed6d77389544838d9d861a038d2c5c5385863ee9a367436770cbf7d21c5e05a991b9e24a33806e9ac985df2448185 languageName: node linkType: hard -"@testing-library/user-event@npm:^13.1.5": - version: 13.5.0 - resolution: "@testing-library/user-event@npm:13.5.0" - dependencies: - "@babel/runtime": "npm:^7.12.5" +"@testing-library/user-event@npm:^14.5.2": + version: 14.5.2 + resolution: "@testing-library/user-event@npm:14.5.2" peerDependencies: "@testing-library/dom": ">=7.21.4" - checksum: 10/e2bdf2b2375d1399a4fd45195705ab0be05f5e3e8220ecbfc26cba98985e45cb505e4e11ed4d909a7052ce90d1e83751cfe21bb1b70fa82d2a2c268370432d8b + checksum: 10/49821459d81c6bc435d97128d6386ca24f1e4b3ba8e46cb5a96fe3643efa6e002d88c1b02b7f2ec58da593e805c59b78d7fdf0db565c1f02ba782f63ee984040 languageName: node linkType: hard @@ -7626,10 +7633,10 @@ __metadata: languageName: node linkType: hard -"@types/aria-query@npm:^4.2.0": - version: 4.2.1 - resolution: "@types/aria-query@npm:4.2.1" - checksum: 10/04f60d7a3938ce1f33810f4cccde95e1fa45d2bb5ab1b7e93a5c331c072a59a9b3b559479b56c59af0170d40d97698e139310fef94904cff44db7151db8b9e15 +"@types/aria-query@npm:^5.0.1": + version: 5.0.4 + resolution: "@types/aria-query@npm:5.0.4" + checksum: 10/c0084c389dc030daeaf0115a92ce43a3f4d42fc8fef2d0e22112d87a42798d4a15aac413019d4a63f868327d52ad6740ab99609462b442fe6b9286b172d2e82e languageName: node linkType: hard @@ -8206,7 +8213,7 @@ __metadata: languageName: node linkType: hard -"@types/react-dom@npm:^18.0.0, @types/react-dom@npm:^18.0.5, @types/react-dom@npm:^18.2.25, @types/react-dom@npm:^18.3.0": +"@types/react-dom@npm:^18.0.5, @types/react-dom@npm:^18.2.25, @types/react-dom@npm:^18.3.0": version: 18.3.0 resolution: "@types/react-dom@npm:18.3.0" dependencies: @@ -9896,6 +9903,15 @@ __metadata: languageName: node linkType: hard +"aria-query@npm:5.3.0": + version: 5.3.0 + resolution: "aria-query@npm:5.3.0" + dependencies: + dequal: "npm:^2.0.3" + checksum: 10/c3e1ed127cc6886fea4732e97dd6d3c3938e64180803acfb9df8955517c4943760746ffaf4020ce8f7ffaa7556a3b5f85c3769a1f5ca74a1288e02d042f9ae4e + languageName: node + linkType: hard + "aria-query@npm:^4.2.2": version: 4.2.2 resolution: "aria-query@npm:4.2.2" @@ -12960,6 +12976,13 @@ __metadata: languageName: node linkType: hard +"dequal@npm:^2.0.3": + version: 2.0.3 + resolution: "dequal@npm:2.0.3" + checksum: 10/6ff05a7561f33603df87c45e389c9ac0a95e3c056be3da1a0c4702149e3a7f6fe5ffbb294478687ba51a9e95f3a60e8b6b9005993acd79c292c7d15f71964b6b + languageName: node + linkType: hard + "destroy@npm:1.2.0": version: 1.2.0 resolution: "destroy@npm:1.2.0" @@ -13147,13 +13170,20 @@ __metadata: languageName: node linkType: hard -"dom-accessibility-api@npm:^0.5.6, dom-accessibility-api@npm:^0.5.9": +"dom-accessibility-api@npm:^0.5.6": version: 0.5.14 resolution: "dom-accessibility-api@npm:0.5.14" checksum: 10/19d7a7de931fcc7d9d67c270341220c6bda97124c3b1444b2bea6e8c6c3964ee09c339e3e69be5b830e3fcb60258d43e6377039974b69c5cec2f75db0114ac59 languageName: node linkType: hard +"dom-accessibility-api@npm:^0.5.9": + version: 0.5.16 + resolution: "dom-accessibility-api@npm:0.5.16" + checksum: 10/377b4a7f9eae0a5d72e1068c369c99e0e4ca17fdfd5219f3abd32a73a590749a267475a59d7b03a891f9b673c27429133a818c44b2e47e32fec024b34274e2ca + languageName: node + linkType: hard + "dom-converter@npm:^0.2.0": version: 0.2.0 resolution: "dom-converter@npm:0.2.0" @@ -19211,12 +19241,12 @@ __metadata: languageName: node linkType: hard -"lz-string@npm:^1.4.4": - version: 1.4.4 - resolution: "lz-string@npm:1.4.4" +"lz-string@npm:^1.5.0": + version: 1.5.0 + resolution: "lz-string@npm:1.5.0" bin: lz-string: bin/bin.js - checksum: 10/da3abc3c15b3f91ab0fba0fe8ea3bb53d3c758d5c50d88d97b759e52d9b5224f8b05edc0e6423bfd448e6bcbe30f79236b7f2e6e7f8a321be62ae77b88092581 + checksum: 10/e86f0280e99a8d8cd4eef24d8601ddae15ce54e43ac9990dfcb79e1e081c255ad24424a30d78d2ad8e51a8ce82a66a930047fed4b4aa38c6f0b392ff9300edfc languageName: node linkType: hard From 97f96adb1904a1b6d69044da81527e27485784e1 Mon Sep 17 00:00:00 2001 From: isqua Date: Fri, 1 Nov 2024 21:27:39 +0100 Subject: [PATCH 2/7] Fix tests after upgrade @testing-library/react --- .../src/query/tests/buildHooks.test.tsx | 30 +++++++++++++------ .../toolkit/src/query/tests/cleanup.test.tsx | 2 +- .../query/tests/refetchingBehaviors.test.tsx | 18 ++++------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/packages/toolkit/src/query/tests/buildHooks.test.tsx b/packages/toolkit/src/query/tests/buildHooks.test.tsx index 6810e75dd8..b413274fcb 100644 --- a/packages/toolkit/src/query/tests/buildHooks.test.tsx +++ b/packages/toolkit/src/query/tests/buildHooks.test.tsx @@ -6,6 +6,7 @@ import { actionsReducer, setupApiStore, useRenderCounter, + waitForFakeTimer, waitMs, withProvider, } from '@internal/tests/utils/helpers' @@ -47,7 +48,7 @@ interface Item { const api = createApi({ baseQuery: async (arg: any) => { - await waitMs(150) + await waitForFakeTimer(150) if (arg?.body && 'amount' in arg.body) { amount += 1 } @@ -915,7 +916,7 @@ describe('hooks tests', () => { resPromise = refetch() }) expect(resPromise).toBeInstanceOf(Promise) - const res = await resPromise + const res = await act(() => resPromise) expect(res.data!.amount).toBeGreaterThan(originalAmount) }) @@ -1095,15 +1096,15 @@ describe('hooks tests', () => { // Allow at least three state effects to hit. // Trying to see if any [true, false, true] occurs. await act(async () => { - await waitMs(1) + await waitForFakeTimer(150) }) await act(async () => { - await waitMs(1) + await waitForFakeTimer(150) }) await act(async () => { - await waitMs(1) + await waitForFakeTimer(150) }) // Find if at any time the isLoading state has reverted @@ -1864,7 +1865,8 @@ describe('hooks tests', () => { expect(screen.getByTestId('isFetching').textContent).toBe('false'), ) - userEvent.hover(screen.getByTestId('highPriority')) + await userEvent.hover(screen.getByTestId('highPriority')) + expect( api.endpoints.getUser.select(USER_ID)(storeRef.store.getState() as any), ).toEqual({ @@ -2001,7 +2003,7 @@ describe('hooks tests', () => { await waitMs(400) // This should run the query being that we're past the threshold - userEvent.hover(screen.getByTestId('lowPriority')) + await userEvent.hover(screen.getByTestId('lowPriority')) expect( api.endpoints.getUser.select(USER_ID)(storeRef.store.getState() as any), ).toEqual({ @@ -2101,7 +2103,7 @@ describe('hooks tests', () => { render(, { wrapper: storeRef.wrapper }) - userEvent.hover(screen.getByTestId('lowPriority')) + await userEvent.hover(screen.getByTestId('lowPriority')) expect( api.endpoints.getUser.select(USER_ID)(storeRef.store.getState() as any), @@ -2993,6 +2995,11 @@ describe('skip behavior', () => { await act(async () => { rerender([1]) }) + + await act(async () => { + await waitForFakeTimer(150) + }) + expect(result.current).toMatchObject({ status: QueryStatus.fulfilled }) await waitMs(1) expect(getSubscriptionCount('getUser(1)')).toBe(1) @@ -3030,6 +3037,11 @@ describe('skip behavior', () => { await act(async () => { rerender([1]) }) + + await act(async () => { + await waitForFakeTimer(150) + }) + expect(result.current).toMatchObject({ status: QueryStatus.fulfilled }) await waitMs(1) expect(getSubscriptionCount('getUser(1)')).toBe(1) @@ -3059,7 +3071,7 @@ describe('skip behavior', () => { ) await act(async () => { - await waitMs(1) + await waitForFakeTimer(150) }) // Normal fulfilled result, with both `data` and `currentData` diff --git a/packages/toolkit/src/query/tests/cleanup.test.tsx b/packages/toolkit/src/query/tests/cleanup.test.tsx index fff0d4f7ad..49b634d7f4 100644 --- a/packages/toolkit/src/query/tests/cleanup.test.tsx +++ b/packages/toolkit/src/query/tests/cleanup.test.tsx @@ -43,7 +43,7 @@ function UsingAB() { } beforeAll(() => { - vi.useFakeTimers() + vi.useFakeTimers({ shouldAdvanceTime: true }) }) test('data stays in store when component stays rendered', async () => { diff --git a/packages/toolkit/src/query/tests/refetchingBehaviors.test.tsx b/packages/toolkit/src/query/tests/refetchingBehaviors.test.tsx index be27d08d9f..96e41b9e10 100644 --- a/packages/toolkit/src/query/tests/refetchingBehaviors.test.tsx +++ b/packages/toolkit/src/query/tests/refetchingBehaviors.test.tsx @@ -71,12 +71,12 @@ describe('refetchOnFocus tests', () => { expect(screen.getByTestId('amount').textContent).toBe('1'), ) + fireEvent.focus(window) + await act(async () => { - fireEvent.focus(window) + await delay(150) }) - await delay(150) - await waitFor(() => expect(screen.getByTestId('amount').textContent).toBe('2'), ) @@ -111,9 +111,7 @@ describe('refetchOnFocus tests', () => { expect(screen.getByTestId('amount').textContent).toBe('1'), ) - act(() => { - fireEvent.focus(window) - }) + fireEvent.focus(window) await delay(150) @@ -165,9 +163,7 @@ describe('refetchOnFocus tests', () => { expect(screen.getByTestId('amount').textContent).toBe('1'), ) - act(() => { - fireEvent.focus(window) - }) + fireEvent.focus(window) expect(screen.getByTestId('isLoading').textContent).toBe('false') await waitFor(() => expect(screen.getByTestId('isFetching').textContent).toBe('true'), @@ -213,9 +209,7 @@ describe('refetchOnFocus tests', () => { expect(getIncrementedAmountState()).not.toBeUndefined() - await act(async () => { - fireEvent.focus(window) - }) + fireEvent.focus(window) await delay(1) expect(getIncrementedAmountState()).toBeUndefined() From 5255770adbdab2983a6336ff2dad586fe67dc3cf Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Thu, 28 Nov 2024 16:53:23 -0500 Subject: [PATCH 3/7] Remove stray console log --- packages/toolkit/src/query/tests/buildHooks.test.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/toolkit/src/query/tests/buildHooks.test.tsx b/packages/toolkit/src/query/tests/buildHooks.test.tsx index b413274fcb..50ff561148 100644 --- a/packages/toolkit/src/query/tests/buildHooks.test.tsx +++ b/packages/toolkit/src/query/tests/buildHooks.test.tsx @@ -466,7 +466,6 @@ describe('hooks tests', () => {