We've just created a small library to mock this in Nodejs.
https://github.com/CureApp/react-native-config-node
Do you have an idea of merging the project?
Hey there!
So sorry for the delay, I'd definitely be down to merge this in to make sure this behaves well with test. Would you be willing to make a stab at a pull request?
Thanks!
I've been able to use this module when testing with mocha by 'simply' adding the following to a file that I require to run tests:
import { NativeModules } from 'react-native';
// http://stackoverflow.com/a/35045012/999076
require('babel-core/register')({
ignore: '/node_modules/(?!Project)/'
});
NativeModules.ReactNativeConfig = {};
Another alternative, for just mocking the Config.FOO usage:
// __mocks__/react-native-config.js
export default {
FOO_BAR: 'baz',
};
Closing for now, still open to ideas merging react-native-config-node or just making testing easier here!
@phillbaker thank you ! works for me :-)
I've been able to use this module when testing with mocha by 'simply' adding the following to a file that I require to run tests:
import { NativeModules } from 'react-native'; // http://stackoverflow.com/a/35045012/999076 require('babel-core/register')({ ignore: '/node_modules/(?!Project)/' }); NativeModules.ReactNativeConfig = {};
jest.doMock('react-native', () => {
// Extend ReactNative
const ReactNative = require.requireActual('react-native');
return Object.setPrototypeOf(
{
// Redefine an export, like a component
NativeModules: {
...ReactNative.NativeModules,
ReactNativeConfig: {
ENV: 'production', // your env key
}
},
Jest -^24.9.0
Works like charm
Most helpful comment
Another alternative, for just mocking the
Config.FOOusage: