I'm upgrading Babel from 6.26.0 to 7.8.3 and some of my tests are now breaking. It appears that the new version is preventing an exported function from being stubbed by Sinon after the upgrade.
Is there a configuration setting or plugin that I need to use as part of the upgrade to get the older behavior?
Here is an example of a test that is breaking:
it('a calls b', function () {
bStub = sinon.stub(B, 'default');
a.do();
expect(bStub.calledOnce).to.be.true; // this used to be true but no is now false
});
The functions are mostly simple but I added some logging code and it appears that B() used to stub as expected when using the older version of Babel but it no longer gets stubbed successfully and the actual B() function is called.
The actual function under test: A.js
A.do = function () {
return B();
};
export default A;
And the function call that is being stubbed out: B.js
export default function B () {
...
};
Some config changes I made as part of the upgrade:
project.json
"devDependencies": {
+ "@babel/cli": "^7.8.3",
+ "@babel/core": "^7.8.3",
+ "@babel/preset-env": "^7.8.3",
- "babel-cli": "^6.5.1",
- "babel-core": "^6.26.0",
- "babel-loader": "^7.1.2",
- "babel-preset-es2015": "^6.5.0",
+ "babel-loader": "^8.0.6",
...
}
.babelrc
{
- "presets": ["es2015"]
+ "presets": ["@babel/preset-env"]
}
webpack.config.json
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules|scripts|dist|build\//,
use: {
loader: 'babel-loader',
options: {
- presets: ['es2015']
+ presets: ['@babel/preset-env']
}
}
}
]
}
Thanks!