Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 1.11 KB

was-called-on.md

File metadata and controls

46 lines (35 loc) · 1.11 KB

Passes if the spy was ever called with obj as its this value.

var obj = { spy: sinon.spy().named('mySpy') };
obj.spy();
expect(obj.spy, 'was called on', obj);

In case of a failing expectation you get the following output:

var another = {};
expect(obj.spy, 'was called on', another);
expected mySpy was called on {}

mySpy(); at theFunction (theFileName:xx:yy)
// expected: was called on {}
//   expected mySpy to be called with {} as this but was called with { spy: mySpy }

You can make this assertion more strict by using the always flag. Then it passes if the spy was always called with obj as its this value.

expect(obj.spy, 'was always called on', obj);

In case of a failing expectation you get the following output:

obj.spy.call({});
expect(obj.spy, 'was always called on', obj);
expected mySpy was always called on { spy: mySpy }

mySpy(); at theFunction (theFileName:xx:yy)
mySpy(); at theFunction (theFileName:xx:yy)
// expected: was called on { spy: mySpy }
//   expected mySpy to be called with { spy: mySpy } as this but was called with {}