var MyClassStub = sinon.createStubInstance(MyClass);
MyClassStub doesn't contain static methods. How to fix that?
var MyClassStub = sinon.createStubInstance(MyClass);
MyClassStub doesn't contain static methods. How to fix that?
static method:
sinon.stub(YourClass, 'yourClassMethod').callsFake(() => {
return {}
})
not static method:
sinon.stub(YourClass.prototype, 'yourClassMethod').callsFake(() => {
return {}
})
Using sinon version 3.1.0 I am able to mock (stub) private static variable using the code given below:
const YourClass = require('./lib/YourClass');
const mockStaticMethod = sinon.stub(YourClass, '_yourStaticMethod').returns('I am called');
The only thing that you have to remember that the first parameter in sinon.stub() method should be the class itself. It should not be object of that class like const yourClassObject = new YourClass();
. The reason is that any object of the class won't let you access static methods.