Giter Site home page Giter Site logo

Comments (7)

phillbaker avatar phillbaker commented on June 26, 2024 3

Another alternative, for just mocking the Config.FOO usage:

// __mocks__/react-native-config.js
export default {
  FOO_BAR: 'baz',
};

from react-native-config.

m-vdb avatar m-vdb commented on June 26, 2024 1

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 = {};

from react-native-config.

pedro avatar pedro commented on June 26, 2024

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!

from react-native-config.

pedro avatar pedro commented on June 26, 2024

Closing for now, still open to ideas merging react-native-config-node or just making testing easier here!

from react-native-config.

dimitridewit avatar dimitridewit commented on June 26, 2024

@phillbaker thank you ! works for me :-)

from react-native-config.

goravsehrawat avatar goravsehrawat commented on June 26, 2024

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

from react-native-config.

wolfag avatar wolfag commented on June 26, 2024

Another alternative, for just mocking the Config.FOO usage:

// __mocks__/react-native-config.js
export default {
  FOO_BAR: 'baz',
};

anyone can confirm this still work?. I tried on my project but not luck

from react-native-config.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.