Stubbing a class without invoking a constructor


You can cre­ate Stub instances using sinon.createStubInstance.

const sinon = require('sinon');
const Foo = require('../Foo.js');
const fooStub = sinon.createStubInstance(Foo);
fooStub.foo {
    bar() {
        returns 'bar';
    }
}

expect(fooStub.foo.bar()).to.equal('bar');

You may also like...