Added ability to unit test features.

This commit is contained in:
Chris
2015-08-31 11:21:01 +02:00
parent 5e32fef364
commit 5055c67f68
10 changed files with 128 additions and 3 deletions
View File
+27
View File
@@ -0,0 +1,27 @@
/*eslint-env node, mocha */
/*global expect */
/*eslint no-console: 0*/
'use strict';
// Uncomment the following lines to use the react test utilities
// import React from 'react/addons';
// const TestUtils = React.addons.TestUtils;
import createComponent from 'helpers/shallowRenderHelper';
import Main from 'components/Main';
describe('MainComponent', () => {
let MainComponent;
beforeEach(() => {
MainComponent = createComponent(Main);
});
it('should have its component name as default className', () => {
expect(MainComponent._store.props.className).to.equal('index');
});
it('should do something!', () => {
expect(true).to.be.true;
});
});
+23
View File
@@ -0,0 +1,23 @@
/**
* Function to get the shallow output for a given component
* As we are using phantom.js, we also need to include the fn.proto.bind shim!
*
* @see http://simonsmith.io/unit-testing-react-components-without-a-dom/
* @author somonsmith
*/
import React from 'react/addons';
const TestUtils = React.addons.TestUtils;
/**
* Get the shallow rendered component
*
* @param {Object} component The component to return the output for
* @param {Object} props [optional] The components properties
* @param {Mixed} ...children [optional] List of children
* @return {Object} Shallow rendered output
*/
export default function createComponent(component, props = {}, ...children) {
const shallowRenderer = TestUtils.createRenderer();
shallowRenderer.render(React.createElement(component, props, children.length > 1 ? children : children[0]));
return shallowRenderer.getRenderOutput();
}
+2
View File
@@ -0,0 +1,2 @@
var testsContext = require.context('.', true, /(Test\.js$)|(Helper\.js$)/);
testsContext.keys().forEach(testsContext);
View File
View File