-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathjest-setup.js
More file actions
57 lines (45 loc) · 1.75 KB
/
jest-setup.js
File metadata and controls
57 lines (45 loc) · 1.75 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
/* eslint-disable no-undef */
import "@testing-library/jest-dom";
import failOnConsole from "jest-fail-on-console";
import { initializeI18n } from "components/TranslationProvider/i18n";
import { failOnConsoleOptions } from "./jest-config/config";
// Fixes element.getTotalLength is not a function. Refer: https://github.com/framer/motion/issues/204
if (!SVGElement.prototype.getTotalLength) {
SVGElement.prototype.getTotalLength = () => 1;
}
//Fixes ReferenceError: ResizeObserver is not defined
global.ResizeObserver = require("resize-observer-polyfill");
//Fixes TypeError: window.matchMedia is not a function
Object.defineProperty(window, "matchMedia", {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: true,
media: query,
onchange: null,
addListener: jest.fn(), // Deprecated
removeListener: jest.fn(), // Deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
})),
});
//Fixes TypeError: errorFormElement?.scrollIntoView is not a function
Element.prototype.scrollIntoView = jest.fn();
Element.prototype.scrollTo = jest.fn();
HTMLCanvasElement.prototype.getContext = jest.fn();
window.scrollTo = jest.fn();
// Fixes "Not implemented: window.getComputedStyle" for Ant Design components
window.getComputedStyle = jest.fn().mockImplementation(element => {
const style = element.style || {};
return {
getPropertyValue: jest.fn(prop => {
if (prop === "visibility") return style.visibility || "visible";
if (prop === "display") return style.display || "block";
return style[prop] || "";
}),
setProperty: jest.fn(),
visibility: style.visibility || "visible",
display: style.display || "block",
};
});
failOnConsole(failOnConsoleOptions);
initializeI18n();