How to stub static methods with sinon in ES6?

Rostislav Shtanko picture Rostislav Shtanko · Jul 6, 2016 · Viewed 11.8k times · Source
var MyClassStub = sinon.createStubInstance(MyClass);

MyClassStub doesn't contain static methods. How to fix that?

Answer

danday74 picture danday74 · Jul 23, 2017

static method:

sinon.stub(YourClass, 'yourClassMethod').callsFake(() => {
  return {}
})

not static method:

sinon.stub(YourClass.prototype, 'yourClassMethod').callsFake(() => {
  return {}
})