react-native-mock
react-native-mock copied to clipboard
Build a way to safely require single modules from react-native
Need to implement:
- flow transforms
- babel transforms
- fbjs transforms
I'm receiving a flow error I guess
react-native-vector-icons/lib/create-icon-set.js:39
function createIconSet(glyphMap : Object, fontFamily : string, fontFile : string) : Function {
^
SyntaxError: Unexpected token :
is there a workaround for this for now?
in our mocha config we do --register
a file that looks like this:
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/)
);
}
return false;
}
});
[...]
I'm receiving this error when I try to run tests with react-native-router-flux
app/node_modules/babel-core/lib/transformation/file/index.js:591
throw err;
^
SyntaxError: app/node_modules/react-native-router-flux/src/menu_burger.png: Unexpected character '�' (1:0)
> 1 | �PNG
| ^
2 |
3 |
this is my testHelper.js file
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;
}
});
and this is my npm test script
"test": "node_modules/.bin/mocha --compilers js:babel-core/register --require testHelper.js **/__test__/*.js",
any workaround to handle this?
@sibeliusseraphini Yes, this occurs when node tries to require an image as JS. See #11 for more discussions