This project was bootstrapped with Create React App.
create-react-app react-mocha-boilerplate
cd react-mocha-boilerplate
npm run eject
npm install chai enzyme mocha react-addons-test-utils sinon --save-dev
npm install babel-preset-es2015 babel-preset-stage-2 --save-dev
......
"scripts": {
"test": "mocha --require ./testSetup.js --compilers babel-core/register ./test/*test.js",
"test:watch": "npm test -- -w"
},
......
'use strict';
import jsdom from 'jsdom';
global.document = jsdom.jsdom('<html><body></body></html>');
global.window = document.defaultView;
global.navigator = window.navigator;
function noop() {
return {};
}
// prevent mocha tests from breaking when trying to require a css file
require.extensions['.css'] = noop;
require.extensions['.svg'] = noop;
import React from 'react'
import { shallow } from 'enzyme'
import { expect } from 'chai'
import App from '../src/App'
const wrapper = shallow(<App />);
describe('(Component) App', () => {
it('renders...', () => {
expect(wrapper).to.have.length(1);
});
});
{
"presets": ["es2015", "stage-2", "react"]
}
npm run test