forked from CMSgov/design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupTests.js
38 lines (32 loc) · 1.01 KB
/
setupTests.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
/**
* setupTests.js
*
* Setup for running tests with `@cmsgov/design-system-scripts`, this file is run before each test file
*/
// Enzyme for React 16
import Adapter from 'enzyme-adapter-react-16';
import { configure } from 'enzyme';
import '@testing-library/jest-dom/extend-expect';
configure({ adapter: new Adapter() });
// following Jest's recommendation: https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
window.matchMedia = (query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // Deprecated
removeListener: jest.fn(), // Deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
});
window.scroll = () => {};
const localStorageMock = (function () {
return {
getItem: jest.fn((itemName) => (itemName === 'CMS_DS_IT_LAST_ACTIVE' ? 1643811720 : null)),
setItem: jest.fn(),
clear: jest.fn(),
};
})();
Object.defineProperty(window, 'localStorage', {
value: localStorageMock,
});