added test boilerplate and helpers
This commit is contained in:
parent
3441a8ec05
commit
3f36bba5fe
10
package.json
10
package.json
|
@ -5,7 +5,9 @@
|
|||
"main": "index.js",
|
||||
"repository": "git@github.com:StephenGrider/ReduxSimpleStarter.git",
|
||||
"scripts": {
|
||||
"start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js"
|
||||
"start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
|
||||
"test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js 'test/**/*.js'",
|
||||
"test:watch": "npm run test -- --watch"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
|
@ -14,6 +16,12 @@
|
|||
"babel-loader": "^6.2.0",
|
||||
"babel-preset-es2015": "^6.1.18",
|
||||
"babel-preset-react": "^6.1.18",
|
||||
"chai": "^3.5.0",
|
||||
"chai-jquery": "^2.0.0",
|
||||
"jquery": "^2.2.1",
|
||||
"jsdom": "^8.1.0",
|
||||
"mocha": "^2.4.5",
|
||||
"react-addons-test-utils": "^0.14.7",
|
||||
"webpack": "^1.12.9",
|
||||
"webpack-dev-server": "^1.14.0"
|
||||
},
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
import { renderComponent , expect } from '../test_helper';
|
||||
import App from '../../src/components/app';
|
||||
|
||||
describe('App' , () => {
|
||||
let component;
|
||||
|
||||
beforeEach(() => {
|
||||
component = renderComponent(App);
|
||||
});
|
||||
|
||||
it('renders something', () => {
|
||||
expect(component).to.exist;
|
||||
});
|
||||
});
|
|
@ -0,0 +1,35 @@
|
|||
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;
|
||||
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};
|
Loading…
Reference in New Issue