I encountered a weird problem when trying to use babel-plugin-rewire
and should.js
assertion library in my tests. With my current configuration I cannot require should
to a variable:
const should = require('should')
console.log('should through variable: ', should) // --> undefined !!!
console.log('should through require: ', require('should')) // --> function should...
Tests are run using command
NODE_ENV=test mocha --compilers js:babel-register --require babel-polyfill --require should
The problem goes away if I comment out the rewire
plugin from my .babelrc
:
{
"presets": ["es2015", "es2015-node4", "async-to-bluebird"],
"env": {
"test": {
// "plugins": ["babel-plugin-rewire"]
}
}
}
... but then I cannot use the rewire functionality.
Do you have any clues how to get babel-plugin-rewire
and should.js
work together?
The used library versions are:
"babel-plugin-rewire": "^1.0.0-rc-3",
"should": "^7.1.0",