Skip to content

Commit 507887e

Browse files
authored
chore(test): update testing libraries and refactor (#3886)
1 parent 3bc2490 commit 507887e

File tree

33 files changed

+1123
-1421
lines changed

33 files changed

+1123
-1421
lines changed

apps/docs/components/sandpack/entries.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ReactDOM.createRoot(document.getElementById("root")).render(
1010
<NextUIProvider>
1111
<div className="w-screen h-screen p-8 flex items-start justify-center">
1212
<App />
13-
</div>
13+
</div>
1414
</NextUIProvider>
1515
</React.StrictMode>
1616
);`;

jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
],
1919
},
2020
transformIgnorePatterns: ["[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"],
21-
setupFilesAfterEnv: ["@testing-library/jest-dom/extend-expect", "./scripts/setup-test.ts"],
21+
setupFilesAfterEnv: ["@testing-library/jest-dom", "./scripts/setup-test.ts"],
2222
globals: {
2323
"ts-jest": {
2424
tsconfig: "tsconfig.json",

package.json

+7-9
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,15 @@
7373
"@swc-node/jest": "^1.5.2",
7474
"@swc/core": "^1.3.35",
7575
"@swc/jest": "^0.2.24",
76-
"@testing-library/dom": "^8.1.0",
77-
"@testing-library/jest-dom": "^5.16.4",
78-
"@testing-library/react": "^14.0.0",
79-
"@testing-library/react-hooks": "^8.0.1",
80-
"@testing-library/user-event": "^14.4.3",
81-
"@types/jest": "^28.1.1",
76+
"@testing-library/dom": "^10.4.0",
77+
"@testing-library/jest-dom": "^6.5.0",
78+
"@testing-library/react": "^16.0.1",
79+
"@testing-library/user-event": "^14.5.2",
80+
"@types/jest": "^29.5.13",
8281
"@types/node": "^15.12.4",
8382
"@types/react": "^18.0.1",
8483
"@types/react-dom": "^18.0.0",
8584
"@types/shelljs": "^0.8.9",
86-
"@types/testing-library__jest-dom": "5.14.5",
8785
"@typescript-eslint/eslint-plugin": "^5.42.0",
8886
"@typescript-eslint/parser": "^5.42.0",
8987
"chalk": "^4.1.2",
@@ -115,8 +113,8 @@
115113
"gray-matter": "^4.0.3",
116114
"husky": "^8.0.1",
117115
"intl-messageformat": "^10.1.0",
118-
"jest": "^28.1.1",
119-
"jest-environment-jsdom": "^28.1.1",
116+
"jest": "^29.7.0",
117+
"jest-environment-jsdom": "^28.1.3",
120118
"jest-watch-typeahead": "1.1.0",
121119
"lint-staged": "^13.0.3",
122120
"npm-check-updates": "^16.10.18",

packages/components/accordion/__tests__/accordion.test.tsx

+20-50
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe("Accordion", () => {
3030

3131
expect(() => wrapper.unmount()).not.toThrow();
3232

33-
expect(spy).toBeCalledTimes(0);
33+
expect(spy).toHaveBeenCalledTimes(0);
3434
});
3535

3636
it("ref should be forwarded", () => {
@@ -121,9 +121,7 @@ describe("Accordion", () => {
121121

122122
expect(button).toHaveAttribute("aria-expanded", "false");
123123

124-
await act(async () => {
125-
await user.click(button);
126-
});
124+
await user.click(button);
127125

128126
expect(button).toHaveAttribute("aria-expanded", "true");
129127
});
@@ -163,18 +161,12 @@ describe("Accordion", () => {
163161
const second = wrapper.getByTestId("item-2");
164162
const secondButton = second.querySelector("button") as HTMLElement;
165163

166-
act(() => {
167-
focus(firstButton);
168-
});
169-
170-
await act(async () => {
171-
await user.keyboard("[ArrowDown]");
172-
});
164+
await focus(firstButton);
165+
await user.keyboard("[ArrowDown]");
173166
expect(secondButton).toHaveFocus();
174167

175-
await act(async () => {
176-
await user.keyboard("[ArrowUp]");
177-
});
168+
await user.keyboard("[ArrowUp]");
169+
178170
expect(firstButton).toHaveFocus();
179171
});
180172

@@ -200,14 +192,10 @@ describe("Accordion", () => {
200192
focus(secondButton);
201193
});
202194

203-
await act(async () => {
204-
await user.keyboard("[Home]");
205-
});
195+
await user.keyboard("[Home]");
206196
expect(firstButton).toHaveFocus();
207197

208-
await act(async () => {
209-
await user.keyboard("[End]");
210-
});
198+
await user.keyboard("[End]");
211199
expect(secondButton).toHaveFocus();
212200
});
213201

@@ -233,9 +221,7 @@ describe("Accordion", () => {
233221
focus(firstButton);
234222
});
235223

236-
await act(async () => {
237-
await user.keyboard("[Tab]");
238-
});
224+
await user.keyboard("[Tab]");
239225
expect(secondButton).toHaveFocus();
240226
});
241227

@@ -276,10 +262,7 @@ describe("Accordion", () => {
276262

277263
expect(button).toHaveAttribute("aria-expanded", "false");
278264

279-
await act(async () => {
280-
await user.click(button);
281-
});
282-
265+
await user.click(button);
283266
expect(button).toHaveAttribute("aria-expanded", "true");
284267
});
285268

@@ -300,17 +283,11 @@ describe("Accordion", () => {
300283

301284
expect(item1.querySelector("[role='region']")).toBeInTheDocument();
302285

303-
await act(async () => {
304-
await user.click(button);
305-
});
306-
286+
await user.click(button);
307287
const item2 = wrapper.getByTestId("item-2");
308288
const button2 = item2.querySelector("button") as HTMLElement;
309289

310-
await act(async () => {
311-
await user.click(button2);
312-
});
313-
290+
await user.click(button2);
314291
expect(item1.querySelector("[role='region']")).toBeInTheDocument();
315292
expect(item2.querySelector("[role='region']")).toBeInTheDocument();
316293
});
@@ -331,29 +308,22 @@ describe("Accordion", () => {
331308

332309
const firstButton = await wrapper.getByRole("button", {name: "Accordion Item 1"});
333310

334-
await act(() => {
311+
act(() => {
335312
focus(firstButton);
336313
});
337-
await act(async () => {
338-
await user.keyboard("[Tab]");
339-
});
314+
315+
await user.keyboard("[Tab]");
340316
expect(input).toHaveFocus();
341317

342-
await act(async () => {
343-
await user.keyboard("aaa");
344-
});
318+
await user.keyboard("aaa");
345319
expect(input).toHaveValue("aaa");
346320

347-
await act(async () => {
348-
await user.keyboard("[ArrowLeft]");
349-
await user.keyboard("b");
350-
});
321+
await user.keyboard("[ArrowLeft]");
322+
await user.keyboard("b");
351323
expect(input).toHaveValue("aaba");
352324

353-
await act(async () => {
354-
await user.keyboard("[ArrowRight]");
355-
await user.keyboard("c");
356-
});
325+
await user.keyboard("[ArrowRight]");
326+
await user.keyboard("c");
357327
expect(input).toHaveValue("aabac");
358328
});
359329

0 commit comments

Comments
 (0)