I am trying to drown out a super call with Sinon and es2016, but I was not very lucky. Any ideas why this is not working?
Starting Node 6.2.2, this can be a problem when implementing classes / constructors.
.babelrc file:
{
"presets": [
"es2016"
],
"plugins": [
"transform-es2015-modules-commonjs",
"transform-async-to-generator"
]
}
Test:
import sinon from 'sinon';
class Foo {
constructor(message) {
console.log(message)
}
}
class Bar extends Foo {
constructor() {
super('test');
}
}
describe('Example', () => {
it('should stub super.constructor call', () => {
sinon.stub(Foo.prototype, 'constructor');
new Bar();
sinon.assert.calledOnce(Foo.prototype.constructor);
});
});
Result:
test
AssertError: expected constructor to be called once but was called 0 times
at Object.fail (node_modules\sinon\lib\sinon\assert.js:110:29)
at failAssertion (node_modules\sinon\lib\sinon\assert.js:69:24)
at Object.assert.(anonymous function) [as calledOnce] (node_modules\sinon\lib\sinon\assert.js:94:21)
at Context.it (/test/classtest.spec.js:21:18)
Note : this problem occurs only for designers. I can track methods inherited from the parent class without any problems.
source
share