1 | import React from 'react'
|
2 | import { ThemeProvider } from 'styled-components'
|
3 | import * as enzyme from 'enzyme'
|
4 | import Adapter from 'enzyme-adapter-react-16'
|
5 | import 'jest-enzyme'
|
6 |
|
7 | import { theme } from './core/theme'
|
8 |
|
9 | const localStorageMock = {
|
10 | getItem: jest.fn(),
|
11 | setItem: jest.fn(),
|
12 | clear: jest.fn(),
|
13 | }
|
14 |
|
15 | const shallowWithTheme = (component) => {
|
16 | const context = enzyme.shallow(<ThemeProvider theme={theme} />)
|
17 | .instance()
|
18 | .getChildContext()
|
19 | return enzyme.shallow(component, { context })
|
20 | }
|
21 |
|
22 | const mountWithTheme = (component) => {
|
23 | const context = enzyme.shallow(<ThemeProvider theme={theme} />)
|
24 | .instance()
|
25 | .getChildContext()
|
26 |
|
27 | return enzyme.mount(component, {
|
28 | context,
|
29 | childContextTypes: ThemeProvider.childContextTypes,
|
30 | })
|
31 | }
|
32 |
|
33 | const renderWithTheme = (component) => {
|
34 | const context = enzyme.shallow(<ThemeProvider theme={theme} />)
|
35 | .instance()
|
36 | .getChildContext()
|
37 |
|
38 | return enzyme.render(component, {
|
39 | context,
|
40 | childContextTypes: ThemeProvider.childContextTypes,
|
41 | })
|
42 | }
|
43 |
|
44 | window.matchMedia = window.matchMedia || function() {
|
45 | return {
|
46 | matches : false,
|
47 | addListener : function() {},
|
48 | removeListener: function() {}
|
49 | };
|
50 | };
|
51 |
|
52 | global.localStorage = localStorageMock;
|
53 | global.shallowWithTheme = shallowWithTheme;
|
54 | global.mountWithTheme = mountWithTheme
|
55 | global.renderWithTheme = renderWithTheme
|
56 |
|
57 | enzyme.configure({ adapter: new Adapter() });
|