forked from mondaycom/vibe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.init.js
40 lines (36 loc) · 1.2 KB
/
jest.init.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
import ReactDOM from "react-dom";
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()
}))
});
ReactDOM.createPortal = node => node;
const { testing } = process.env;
const TESTING_STORYBOOK = testing === "storybook";
if (TESTING_STORYBOOK) {
jest.mock("react-transition-group", () => {
const FakeTransition = jest.fn(({ children }) => children);
const FakeCSSTransition = jest.fn(props => (props.in ? <FakeTransition>{props.children}</FakeTransition> : null));
return { CSSTransition: FakeCSSTransition, Transition: FakeTransition, SwitchTransition: FakeTransition };
});
}
const error = console.error;
console.error = function (warning) {
if (
/(Invalid prop|Failed prop type)/.test(warning) &&
!warning.includes("of value `not valid`") &&
!warning.includes("`ForwardRef`.") &&
!warning.includes("children")
) {
throw new Error(warning);
}
error.apply(console, arguments);
};