[英]Stubbing an ES6 class method using Mocha and Sinon in NodeJS
Is there a way to stub an ES6 class method using Mocha/Sinon? 有没有办法使用Mocha / Sinon存根ES6类方法?
I'm trying to do this... 我正试图这样做......
sinon.stub(Factory, 'announce');
but I just get the following error... 但我得到以下错误......
TypeError: Attempted to wrap undefined property announce as function
Instance methods are still placed on the prototype object of a class to be inherited from, not on its constructor, even if the class
syntax obscures that a bit. 实例方法仍然放在要继承的类的原型对象上,而不是放在其构造函数上,即使class
语法模糊了一点。 Use 使用
sinon.stub(Factory.prototype, 'announce');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.