-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.setup.js
39 lines (36 loc) · 1008 Bytes
/
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
import 'jest-dom/extend-expect'
import 'react-testing-library/cleanup-after-each'
import React from 'react'
import {fromJS} from 'immutable'
import {createStore} from 'redux'
import {combineReducers} from 'redux-immutable'
import {reducer as formLayoutReducer} from './src/index'
import {render} from 'react-testing-library'
import {Provider} from 'react-redux'
import {DndProvider} from 'react-dnd'
import TestBackend from 'react-dnd-test-backend'
const reducer = combineReducers({
[formLayoutReducer.key]: formLayoutReducer
})
global.createStore = (initialState = {}) => createStore(
reducer,
fromJS(initialState)
)
global.render = (sut, {store} = {}) => { // sut = subject under test
const Test = class extends React.Component {
render () {
return sut
}
}
const result = render((
<DndProvider backend={TestBackend}>
<Provider store={store || global.createStore()}>
<Test />
</Provider>
</DndProvider>
))
return {
...result,
store
}
}