Stopping an ES6 class method using Mocha and Sinon in NodeJS

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

I'm trying to do it ...

sinon.stub(Factory, 'announce'); 

but I just get the following error ...

 TypeError: Attempted to wrap undefined property announce as function 
+8
javascript stub mocha sinon
source share
1 answer

Instance methods are still placed in the prototype object of the class inherited from it, and not its constructor, even if the class syntax fades a bit. Use

 sinon.stub(Factory.prototype, 'announce'); 
+17
source share

All Articles