-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.js
84 lines (70 loc) · 2.1 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
global.storyOf = function(name, props, impl) {
describe(name, () => impl && impl(props));
};
// mock
jest.mock('apollo-link-http');
const React = require('react');
class Link extends React.Component {
render() {
const { to, children, ...rest } = this.props;
return React.createElement('a', { ...rest, href: to }, children);
}
}
const { withRouter } = require('react-router-dom');
jest.mock('react-router-dom', () => ({
Link,
Prompt: () => React.createElement('div', { style: { display: 'none' } }, 'Blocker'),
withRouter: component => props =>
React.createElement(component, { ...props, location: { pathname: 'home' } })
}));
// NOTE: DISABLE THIS IF GETTING: ECONNREFUSED 127.0.0.1:9838
require('jest-spy-serialiser').registerSpy();
const css = require('css');
const stringify = css.stringify;
css.stringify = ast => {
let result = stringify(ast);
result = `<style>\n${result}</style>`;
return result;
};
// setup semantic ui
if (!window.localStorage) {
window.localStorage = { debug: false };
}
const mockedWarn = jest.spyOn(global.console, 'warn');
const mockedError = jest.spyOn(global.console, 'error');
// override it
const itOrig = it;
it = function(name, impl) {
mockedWarn.mockReset();
mockedError.mockReset();
itOrig.call(this, name, () => {
const result = impl();
expect(mockedWarn).not.toBeCalled();
expect(mockedError).not.toBeCalled();
return result;
});
};
const Mui = ({ children, ...rest }) => React.createElement('div', { ...rest }, children);
jest.mock('react-transition-group', () => ({
CSSTransitionGroup: ({ children }) => React.createElement(React.Fragment, {}, children),
TransitionGroup: ({ children }) => React.createElement(React.Fragment, {}, children)
}));
// jest.mock('semantic-ui-react', () => ({
// Checkbox: Mui,
// Radio: Mui,
// Input: Mui,
// TextArea: Mui,
// Menu: Mui,
// MenuItem: Mui,
// Icon: Mui,
// Image: Mui,
// Segment: Mui,
// Input: Mui,
// Header: Mui,
// HeaderItem: Mui,
// List: Mui,
// ListItem: Mui,
// Message: Mui,
// Grid: Mui
// }));
const { Checkbox } = require('semantic-ui-react');