To stub a class method with Sinon.js and JavaScript, we call the stub
method.
For instance, we write
sinon.stub(YourClass.prototype, "myMethod").callsFake(() => {
return {};
});
to call stub
with YourClass.prototype
to stub the myMethod
instance method on YourClass
.
We call callFake
with the mock function for the myMethod
method.
Likewise, for static class methods, we write
sinon.stub(YourClass, "myStaticMethod").callsFake(() => {
return {};
});
to mock the YourClass.myStaticMethod
static method with stub
.