Created
June 27, 2016 18:41
-
-
Save linuxenko/cd17ae9e667a9592fbfa1107b6c2a1c3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 _$ from 'jquery'; | |
| import React from 'react'; | |
| import ReactDOM from 'react-dom'; | |
| import TestUtils from 'react-addons-test-utils'; | |
| import jsdom from 'jsdom'; | |
| import chai, { expect } from 'chai'; | |
| import chaiJquery from 'chai-jquery'; | |
| import { Provider } from 'react-redux'; | |
| import { createStore } from 'redux'; | |
| import reducers from '../src/reducers'; | |
| global.document = jsdom.jsdom('<!doctype html><html><body></body></html>'); | |
| global.window = global.document.defaultView; | |
| global.navigator = global.window.navigator; | |
| const $ = _$(window); | |
| chaiJquery(chai, chai.util, $); | |
| function renderComponent(ComponentClass, props = {}, state = {}) { | |
| const componentInstance = TestUtils.renderIntoDocument( | |
| <Provider store={createStore(reducers, state)}> | |
| <ComponentClass {...props} /> | |
| </Provider> | |
| ); | |
| return $(ReactDOM.findDOMNode(componentInstance)); | |
| } | |
| $.fn.simulate = function(eventName, value) { | |
| if (value) { | |
| this.val(value); | |
| } | |
| TestUtils.Simulate[eventName](this[0]); | |
| }; | |
| export {renderComponent, expect}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment