Skip to content

Instantly share code, notes, and snippets.

@alanshaw
Created December 1, 2016 17:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanshaw/5002182652163a1c8c3a8ed2c25eee1d to your computer and use it in GitHub Desktop.
Save alanshaw/5002182652163a1c8c3a8ed2c25eee1d to your computer and use it in GitHub Desktop.
Using react-native-config-node with jest and other test runners

I’ve figured out how to use react-native-config-node with other test runners (I'm using jest) that might be a bit simpler and more generic than the method described in the README:

I installed the two modules:

npm install react-native-config-node babel-plugin-import-rename --save-dev

...and added the following config to my .babelrc:

{
  "presets": ["react-native"],
  "env": {
    "test": {
      "plugins": [
        [
          "import-rename",
          {
            "^react-native-config$": "react-native-config-node"
          }
        ]
      ]
    }
  }
}
@spsaucier
Copy link

This is an excellent drop-in fix, thanks.

@mguay22
Copy link

mguay22 commented Jul 25, 2019

Awesome!

@sammysium
Copy link

I am still not able to get it work? Can you help? My package.json is jest node is:


  "jest": {
    "preset": "react-native",
    "moduleDirectories": [
      "node_modules",
      "src"
    ],
    "transform": {
      "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
    },
    "transformIgnorePatterns": [
      "node_modules/(?!((jest-)?react-native|@react-native-community/.*|react-navigation|react-navigation-drawer|@react-navigation/.*))"
    ]
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment