-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.js
34 lines (29 loc) · 1.01 KB
/
jest.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
// Optional: configure or set up a testing framework before each test.
// If you delete this file, remove `setupFilesAfterEnv` from `jest.config.js`
// Used for __tests__/testing-library.js
// Learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
// https://github.com/pacocoursey/next-themes/issues/21
let localStorageMock;
beforeAll(() => {
// Create a mock of the window.matchMedia function
global.matchMedia = jest.fn((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
}));
// Create mocks of localStorage getItem and setItem functions
global.Storage.prototype.getItem = jest.fn((key) => localStorageMock[key]);
global.Storage.prototype.setItem = jest.fn((key, value) => {
localStorageMock[key] = value;
});
});
beforeEach(() => {
// Clear the localStorage-mock
localStorageMock = {};
});