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
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
Share
Improve this question
asked May 26, 2016 at 21:47
michaelmichael
4,4836 gold badges41 silver badges57 bronze badges
2
|
1 Answer
Reset to default 22Instance 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');
Factory.prototype
? I guess it's not a static method. – Bergi Commented May 27, 2016 at 0:01