-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.setup.js
44 lines (35 loc) · 1.03 KB
/
tests.setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { afterAll, afterEach, beforeEach, beforeAll, expect, vi } from "vitest";
import { server } from "./test-utils/mocks/server";
import { cleanup } from "@testing-library/react";
import matchers from "@testing-library/jest-dom/matchers";
beforeEach(() => {
localStorage.clear();
vi.clearAllMocks();
});
// ----------------------
// RTL related extensions
// ----------------------
// extends Vitest's expect method with methods from react-testing-library
expect.extend(matchers);
// runs a cleanup after each test case (e.g. clearing jsdom)
afterEach(() => {
cleanup();
});
// --------------------------------
// Mock service worker server setup
// --------------------------------
// Establish API mocking before all tests.
beforeAll(() => {
server.listen({
onUnhandledRequest: "error",
});
});
// Reset any request handlers that we may add during the tests,
// so they don't affect other tests.
beforeEach(() => {
server.resetHandlers();
});
// Clean up after the tests are finished.
afterAll(() => {
server.close();
});