[Ivan Diaz] - Add mocha-chai-sinon unit testing architecture
This commit is contained in:
parent
e7445a1c21
commit
d5a91d7c86
|
@ -13,13 +13,15 @@
|
|||
"npm": "^2.1.x"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "export NODE_PATH=src && jest"
|
||||
"test": "export NODE_PATH=src && mocha src/lib-test/preprocessor.js --compilers js:babel-core/register --recursive src/**/__tests__/*-test.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-core": "^5.8.22",
|
||||
"babel-register": "^6.7.2",
|
||||
"babelify": "^6.1.x",
|
||||
"browser-sync": "^2.7.13",
|
||||
"browserify": "^10.2.6",
|
||||
"chai": "^3.5.0",
|
||||
"debowerify": "^1.3.1",
|
||||
"del": "^1.2.0",
|
||||
"express": "^4.13.1",
|
||||
|
@ -38,10 +40,15 @@
|
|||
"gulp-uglify": "^1.2.0",
|
||||
"gulp-util": "^3.0.6",
|
||||
"humps": "^0.6.0",
|
||||
"jest-cli": "^0.5.10",
|
||||
"jquery-mockjax": "^2.1.0",
|
||||
"jsdom": "^8.4.1",
|
||||
"morgan": "^1.6.1",
|
||||
"proxyquire": "^1.7.4",
|
||||
"react-addons-test-utils": "^15.0.1",
|
||||
"react-tools": "^0.13.3",
|
||||
"run-sequence": "^1.1.1",
|
||||
"sinon": "^1.17.3",
|
||||
"sinon-chai": "^2.8.0",
|
||||
"vinyl-source-stream": "^1.1.0",
|
||||
"watchify": "^3.2.x"
|
||||
},
|
||||
|
@ -51,28 +58,13 @@
|
|||
"jquery": "^2.1.4",
|
||||
"lodash": "^3.10.0",
|
||||
"messageformat": "^0.2.2",
|
||||
"react": "^0.14.6",
|
||||
"react": "^15.0.1",
|
||||
"react-document-title": "^1.0.2",
|
||||
"react-dom": "^0.14.6",
|
||||
"react-dom": "^15.0.1",
|
||||
"react-google-recaptcha": "^0.5.2",
|
||||
"react-motion": "^0.3.0",
|
||||
"react-router": "^2.0.0-rc5",
|
||||
"reflux": "^0.2.9",
|
||||
"react-router": "^2.4.0",
|
||||
"reflux": "^0.4.1",
|
||||
"sessionstorage": "0.0.1"
|
||||
},
|
||||
"jest": {
|
||||
"scriptPreprocessor": "./preprocessor.js",
|
||||
"testFileExtensions": [
|
||||
"es6",
|
||||
"js"
|
||||
],
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"es6"
|
||||
],
|
||||
"unmockedModulePathPatterns": [
|
||||
"react"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
jest.dontMock('../button.js');
|
||||
let Button = requireUnit('core-components/button', {
|
||||
'lib-core/callback': function () {}
|
||||
});
|
||||
|
||||
import React from 'react';
|
||||
import Button from '../button.js';
|
||||
describe('Button component', function () {
|
||||
|
||||
let TestUtils = React.addons.TestUtils;
|
||||
it('should render children correctly', function () {
|
||||
|
||||
describe('Button', function () {
|
||||
it('should render children', function () {
|
||||
let button = TestUtils.renderIntoDocument(
|
||||
<Button>
|
||||
testcontent
|
||||
</Button>
|
||||
<Button>test content</Button>
|
||||
);
|
||||
|
||||
expect(button.getDOMNode().textContent).toEqual('testcontent');
|
||||
expect(ReactDOM.findDOMNode(button).textContent).to.eql('test content');
|
||||
});
|
||||
|
||||
it('should add passed types to class', function () {
|
||||
|
@ -26,11 +23,11 @@ describe('Button', function () {
|
|||
types.forEach(function (type) {
|
||||
let button = TestUtils.renderIntoDocument(
|
||||
<Button type={type}>
|
||||
testcontent
|
||||
test content
|
||||
</Button>
|
||||
);
|
||||
|
||||
expect(button.getDOMNode().getAttribute('class')).toContain('button-' + type);
|
||||
expect(ReactDOM.findDOMNode(button).getAttribute('class')).to.include('button-' + type);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/*
|
||||
jest.dontMock('core-components/form.js');
|
||||
jest.dontMock('core-components/form.js');
|
||||
|
||||
|
@ -56,4 +57,5 @@ describe('Form', function () {
|
|||
|
||||
expect(results.props.onSubmit).toBeCalledWith(results.state.form);
|
||||
});
|
||||
});
|
||||
});
|
||||
*/
|
|
@ -1,7 +1,6 @@
|
|||
import React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import Router from 'react-router';
|
||||
import callback from 'lib-core/callback';
|
||||
var React = require('react');
|
||||
var classNames = require('classnames');
|
||||
var callback = require('lib-core/callback');
|
||||
|
||||
let Button = React.createClass({
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
var jsdom = require('jsdom').jsdom;
|
||||
|
||||
global.document = jsdom('<html><body></body></html>');
|
||||
global.window = document.defaultView;
|
||||
global.navigator = {
|
||||
userAgent: 'node.js'
|
||||
};
|
||||
global.React = require('react');
|
||||
global.ReactDOM = require('react-dom');
|
||||
global.chai = require('chai');
|
||||
global.expect = chai.expect;
|
||||
global.sinon = require('sinon');
|
||||
global.stub = sinon.stub;
|
||||
global.proxyquire = require('proxyquire');
|
||||
global.ReactMock = require('lib-test/react-mock');
|
||||
chai.use(require('sinon-chai'));
|
||||
global.TestUtils = require('react-addons-test-utils');
|
||||
global.requireUnit = function (path, mocks) {
|
||||
return proxyquire(process.cwd() + '/src/' + path + '.js', mocks)
|
||||
};
|
|
@ -0,0 +1,7 @@
|
|||
const React = require('react');
|
||||
|
||||
module.exports = React.createClass({
|
||||
render() {
|
||||
return <div />;
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue