jam

jest-alias-module-loader

Jest doesn't really have a simple way of globally replacing certain modules, but I've come up with a couple. Firstly, the hacky and gross way to [replace modules is by using a regexp replace in the preprocessor](https://github.com/facebook/react/pull/4656

Showing:

Popularity

Downloads/wk

48

Maintenance

No Maintenance Data Available

Package

Dependencies

1

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

jest-alias-module-loader

Jest doesn't really have a simple way of globally replacing certain modules, but I've come up with a couple. Firstly, the hacky and gross way to replace modules is by using a regexp replace in the preprocessor. But let's not do that. Instead, this module extends the default HasteModuleLoader to allow us to alias some modules at require time:

// test/aliasedModuleLoader.js

var JestAliasModuleLoader = require('jest-alias-module-loader');

module.exports = JestAliasModuleLoader({
   aliasedModules: {
    // use compiled react for faster loading
    'react': 'react/dist/react-with-addons',
    'react/addons': 'react/dist/react-with-addons',
  },
});

To use this, just add a line to your Jest config (eg. in package.json):

{
  "jest": {
    "moduleLoader": "<rootDir>/test/aliasedModuleLoader.js"
  }
}

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial