is it possible to make sinon spy on function expressions? Look this code for example.
function one() { return 1; }
function two() { return 2; }
function three() { return 3; }
function myMethod() {
var n1 = one();
var n2 = two();
var n3 = three();
return n1 + n2 + n3;
}
QUnit.module('My test');
QUnit.test('testing functions', (assert) => {
assert.expect(3);
const spyOne = sinon.spy(one);
const spyTwo = sinon.spy(two);
const spyThree = sinon.spy(three);
myMethod();
assert.ok(spyOne.called, "called one");
assert.ok(spyTwo.called, "called two");
assert.ok(spyThree.called, "called three");
sinon.restore();
});
Even though I call myMethod()
and I have spies on one - two - three
I still get false on one.called
(same for two
and three
)
What am I missing here?
Thanks!