Created
October 13, 2016 08:12
-
-
Save Calamari/5d6b44b30236614efca72cf7502a3182 to your computer and use it in GitHub Desktop.
React JSDom testing (without Karma) but with coverage
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
npm install --save-dev babel-cli babel-core babel-plugin-__coverage__ enzyme chai-enzyme jsdom-global mocha-jsdom nyc |
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
{ | |
"nyc": { | |
"sourceMap": false, | |
"instrument": false, | |
"include": [ | |
"test/**/*.js" | |
], | |
"reporter": [ | |
"lcov", | |
"html", | |
"cobertura" | |
], | |
"report-dir": "./build/coverage/" | |
}, | |
"scripts": { | |
"test:coverage": "NODE_ENV=test ./node_modules/.bin/nyc npm test $(find src/js -name \"*.js\")", | |
"test:watch": "NODE_ENV=test ./node_modules/.bin/mocha --watch --recursive --reporter min test/**/*test.js", | |
"test": "NODE_ENV=test ./node_modules/.bin/mocha --recursive --reporter min test/**/*test.js", | |
"test:jenkins": "NODE_ENV=test ./node_modules/.bin/mocha --recursive --reporter dot --reporter mocha-junit-reporter --reporter-options mochaFile=./build/test-results.xml src/js/**/__tests__/*.js" | |
} | |
} |
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
// setup the fake DOM environment. | |
// | |
// Note that we use the synchronous jsdom.jsdom() API | |
// instead of jsdom.env() because the 'document' and 'window' | |
// objects must be available when React is require()-d for | |
// the first time. | |
import jsdom from 'jsdom'; | |
const setupFakeDOM = () => { | |
if (typeof document !== 'undefined') { | |
return; | |
} | |
global.document = jsdom.jsdom('<html><body></body></html>'); | |
global.window = document.defaultView; | |
global.navigator = window.navigator; | |
}; | |
setupFakeDOM(); |
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
--require babel-register | |
--require jsdom-global/register | |
--require test/setupMocha.js | |
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 chai from 'chai'; | |
import sinon from 'sinon'; | |
import chaiEnzyme from 'chai-enzyme'; | |
import sinonChai from 'sinon-chai'; | |
import chaiAsPromised from 'chai-as-promised'; | |
import './includes/setupFakeDom'; | |
chai.use(chaiEnzyme()); | |
chai.use(sinonChai); | |
chai.use(chaiAsPromised); | |
global.expect = chai.expect; | |
global.sinon = sinon; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment