在 NodeJS 中使用 Mocha 和 Sinon 存根 ES6 class 方法

Stubbing an ES6 class method using Mocha and Sinon in NodeJS

有没有办法使用 Mocha/Sinon 存根 ES6 class 方法?

我正在尝试这样做...

sinon.stub(Factory, 'announce');

但我只是收到以下错误...

TypeError: Attempted to wrap undefined property announce as function

实例方法仍然放置在要继承的 class 的原型对象上,而不是在其构造函数上,即使 class 语法有点模糊。使用

sinon.stub(Factory.prototype, 'announce');