-
-
Save Keksike/8afd4787f80c08e4e6d36c24a7886510 to your computer and use it in GitHub Desktop.
react-native enzyme test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import createTestApp from '../testHelper'; | |
import MyContainer from '../../app/modules/MyContainer'; | |
describe('<MyContainer>', () => { | |
let view; | |
let store; | |
beforeEach(async () => { | |
const container = createTestApp(<MyContainer/>) | |
view = container.view; | |
store = container.store; | |
}); | |
console.log(view); | |
console.log(store); | |
it('should test', () => { | |
expect('foo').toBe('foo'); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this file is ran before any other test files | |
import Enzyme from 'enzyme'; | |
import Adapter from 'enzyme-adapter-react-16'; | |
Enzyme.configure({adapter: new Adapter()}); | |
// This will mutate `react-native`'s require cache with `react-native-mock-render`'s. | |
require('react-native-mock-render/mock'); | |
// do this so we can use Enzyme mount with React-Native | |
// https://blog.joinroot.com/mounting-react-native-components-with-enzyme-and-jsdom/ | |
const jsdom = require('jsdom').jsdom; | |
global.document = jsdom(''); | |
global.window = document.defaultView; | |
Object.keys(document.defaultView).forEach((property) => { | |
if (typeof global[property] === 'undefined') { | |
global[property] = document.defaultView[property]; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import Enzyme, {mount} from 'enzyme'; | |
import {Provider} from 'react-redux'; | |
import {applyMiddleware, createStore, compose} from 'redux'; | |
import * as reduxLoop from 'redux-loop'; | |
import Adapter from 'enzyme-adapter-react-16'; | |
Enzyme.configure({adapter: new Adapter()}); | |
import middleware from '../app/redux/middleware'; | |
import reducer from '../app/redux/reducer'; | |
const enhancer = compose( | |
applyMiddleware(...middleware), | |
reduxLoop.install() | |
); | |
export default function createTestApp(element, initialState) { | |
const store = createStore(reducer, initialState, enhancer); | |
const view = mount( | |
<Provider store={store}> | |
{element} | |
</Provider> | |
); | |
return {view, store}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment