Problem
In our codebase we have a problem with sinon which can be reproduced with the code snipped below. The thing is that it seems to be that indirect called spies return force false
, the console.log
clearly states that the method is called but the spy.called
remains false
.
Code
The following CDN's can be used for the html:
//cdnjs.cloudflare.com/ajax/libs/sinon.js/1.7.3/sinon-min.js //cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js
main.js
require(['myModule'], function(module) { //using sinon var methodCallerSpy = sinon.spy(module, 'methodCaller') console.log(methodCallerSpy); // methodCaller module.methodCaller(); console.log(methodCallerSpy.called); //true var methodSpy = sinon.spy(module, 'method'); console.log(methodSpy); //method module.methodCaller(); console.log(methodSpy.called); // false module.method(); console.log(methodSpy.called); // true });
And the module
define(function() { const method = () => console.log('method called by methodCaller'); const methodCaller = () => method(); return{ method, methodCaller } });