简体   繁体   中英

Stubbing an ES6 class method using Mocha and Sinon in NodeJS

Is there a way to stub an ES6 class method using Mocha/Sinon?

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. Use

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM