Skip to content

Instantly share code, notes, and snippets.

@jlyman
Last active April 4, 2016 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlyman/09d42c856903abd48948daa9ed64c617 to your computer and use it in GitHub Desktop.
Save jlyman/09d42c856903abd48948daa9ed64c617 to your computer and use it in GitHub Desktop.
Example of getting Mocha going with React Native
{
"presets": ["react-native"]
}
{
"name": "MochaTestableApp",
...
"scripts": {
...
"test": "mocha --require test/testhook --compilers js:babel-register --recursive",
},
...
}
// The purpose of this file is to ensure
// the babel transpiler is activated prior to any
// test code, and using the same babel options
/* eslint semi: [2, "always"] */
const fs = require('fs');
const path = require('path');
const config = getBabelRC();
function getBabelRC() {
const rcpath = path.join(__dirname, '..', '.babelrc');
const source = fs.readFileSync(rcpath).toString();
return JSON.parse(source);
}
config.ignore = (filename) => {
if (!(/\/node_modules\//).test(filename)) {
return false; // if not in node_modules, we want to compile it
} else if ((/\/node_modules\/react-native\//).test(filename)) {
// its RN source code, so we want to compile it
return false;
}
// else it's in node modules and NOT RN source code
return true;
};
require('babel-register')(config);
global.__DEV__ = true;
// Now get some global things available
const chai = require('chai');
const sinon = require('sinon');
const dirtyChai = require('dirty-chai');
const chaiImmutable = require('chai-immutable');
const expect = chai.expect;
const should = chai.should();
chai.use(dirtyChai);
// chai.use(chaiImmutable);
global.chai = chai;
global.expect = expect;
global.should = should;
global.sinon = sinon;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment