New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues with mocking interfering with 3rd-party node modules #23
Comments
Also, worth noting that a simple test on a component with no 3rd party node modules passes, if it's the only test running in the suite.
|
@rlau1115 I'm wondering if you found a fix or work around, facing the same issue 😞 |
Unfortunately no :( Had to skip testing since I was under the gun for a release. |
@rlau1115 Ah! :( thank you for the quick reply 😃 |
+1 |
@rlau1115 Looks like some kind of problem in the code of exponent. The mock for |
hey @RealOrangeOne can u provide an example or snippet of using Mockery to handle |
@sibeliusseraphini Unfortunately the code I used is closed source by my company. I think that's more an issue for the |
this is my testHelper.js require('babel-polyfill');
require('react-native-mock/mock');
// require('babel-core/register')({
// ignore: function(packageName) {
// if (packageName.match(/node_modules/)) {
// return !(packageName.match(/react-native-vector-icons/)
// || packageName.match(/react-native-animatable/)
// || packageName.match(/react-native-router-flux/)
// || packageName.match(/react-native-tab-navigator/)
// );
// }
// return false;
// }
// });
var fs = require('fs');
var path = require('path');
function getBabelRC() {
var rcpath = path.join(__dirname, '.babelrc');
var source = fs.readFileSync(rcpath).toString();
return JSON.parse(source);
}
var config = getBabelRC();
config.ignore = function(filename) {
if (!(/\/node_modules\//).test(filename)) {
console.log(filename, 'FALSE');
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
console.log(filename, 'FALSE');
return false;
} else {
console.log(filename, 'TRUE');
// it's in node modules and NOT RN source code
return true;
}
};
require("babel-register")(config);
global.__DEV__ = true;
// var chai = require('chai');
// var dirtyChai = require('dirty-chai');
// chai.use(dirtyChai);
import chai from 'chai';
import dirtyChai from 'dirty-chai';
// import chaiImmutable from 'chai-immutable';
chai.use(dirtyChai);
//chai.use(chaiImmutable);
import mockery from "mockery";
mockery.enable();
mockery.registerMock('./node_modules/react-native-router-flux/src/menu_burger.png', 0); and this is my "test": "node_modules/.bin/mocha --compilers js:babel-core/register --require testHelper.js **/__test__/*.js", |
only the image part is not working properly |
Youre not setting up mockery correctly, the path is the path it imports not the path to the file. Please see mockery docs |
How can I add some custom mock for some custom library like https://github.com/luggg/react-native-config? |
Using mockery http://stackoverflow.com/a/37655424/168012 |
config.ignore function suggested by @sibelius worked for me - was having issues with spread operator in a 3rd party module |
I'm having some issues getting a basic test to compile. I'm fairly new to React Native / Mocha / Babel so any insight would be helpful.
I followed your advice regarding forcing babel to compile node modules here, with some modifications of my own due to some problematic modules. However, now the issue seems to be that there is a conflict between react-native-mock getting in the way of an external node module ("react-native-router-flux" in this case) from functioning properly.
Any thoughts would be greatly appreciated!
This is the error that I get when running the tests.
The text was updated successfully, but these errors were encountered: