2019-10-28 17:09:48 +00:00
|
|
|
import { configure } from 'enzyme';
|
2021-08-30 12:13:58 +00:00
|
|
|
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
|
2019-11-02 09:27:36 +00:00
|
|
|
import { GlobalWithFetchMock } from 'jest-fetch-mock';
|
2021-03-23 22:55:52 +00:00
|
|
|
import 'mutationobserver-shim'; // Needed for CodeMirror.
|
2019-10-28 17:09:48 +00:00
|
|
|
import './globals';
|
2021-09-07 14:34:12 +00:00
|
|
|
import 'jest-canvas-mock';
|
2019-10-28 17:09:48 +00:00
|
|
|
|
|
|
|
configure({ adapter: new Adapter() });
|
2019-11-02 09:27:36 +00:00
|
|
|
const customGlobal: GlobalWithFetchMock = global as GlobalWithFetchMock;
|
|
|
|
customGlobal.fetch = require('jest-fetch-mock');
|
|
|
|
customGlobal.fetchMock = customGlobal.fetch;
|
2021-03-23 22:55:52 +00:00
|
|
|
|
2021-09-08 15:24:54 +00:00
|
|
|
// https://stackoverflow.com/questions/39830580/jest-test-fails-typeerror-window-matchmedia-is-not-a-function
|
|
|
|
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
|
|
|
|
Object.defineProperty(window, 'matchMedia', {
|
|
|
|
writable: true,
|
|
|
|
value: jest.fn().mockImplementation((query) => ({
|
|
|
|
matches: false,
|
|
|
|
media: query,
|
|
|
|
onchange: null,
|
|
|
|
addListener: jest.fn(), // Deprecated
|
|
|
|
removeListener: jest.fn(), // Deprecated
|
|
|
|
addEventListener: jest.fn(),
|
|
|
|
removeEventListener: jest.fn(),
|
|
|
|
dispatchEvent: jest.fn(),
|
|
|
|
})),
|
|
|
|
});
|
|
|
|
|
2021-03-23 22:55:52 +00:00
|
|
|
// CodeMirror in the expression input requires this DOM API. When we upgrade react-scripts
|
|
|
|
// and the associated Jest deps, hopefully this won't be needed anymore.
|
2021-09-03 15:41:20 +00:00
|
|
|
document.getSelection = function () {
|
2021-03-23 22:55:52 +00:00
|
|
|
return {
|
2021-09-03 15:41:20 +00:00
|
|
|
addRange: function () {
|
2021-03-23 22:55:52 +00:00
|
|
|
return;
|
|
|
|
},
|
2021-09-03 15:41:20 +00:00
|
|
|
removeAllRanges: function () {
|
2021-03-23 22:55:52 +00:00
|
|
|
return;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|