We understand you have a problem and are in a hurry, but please provide us with some info to make it much more likely for your issue to be understood, worked on and resolved quickly.
What did you expect to happen?
I expected the test to process the stub... Your documentation states it does:
http://sinonjs.org/releases/v2.3.5/assertions/
Sinon.JS ships with a set of assertions that mirror most behavior verification methods and properties on spies and stubs. The advantage of using the assertions is that failed expectations on stubs and spies can be expressed directly as assertion failures with detailed and helpful error messages.
The assertions can be used with either spies or stubs.
What actually happens
expected [AssertError: fake is not a spy] to equal null
How to reproduce
Describe with code how to reproduce the faulty behaviour,
or link to code on JSBin or similar
describe('example test', () => {
it('should evaluate sinon.assert.calledWith', () => {
const stub = sinon.stub();
const call1 = stub.onCall(0).resolves(true).stub;
const itemToEval = (option) => {
return stub(option);
};
return itemToEval(1).then(data => {
expect(data).to.equal(true); //passes
sinon.assert.calledWith(call1, 1); //fake is not a spy
});
});
});
Really long code sample or stacktrace
If you need to provide a dump of a stack trace or
other lengthy material, such as 80 lines of example code,
please stuff it in a `<details>` tag such as this
to make the issue more readable. Thanks.
You are using the .stub property. That is an internal detail of Sinon. The stub we talk about is the one returned from the stub() method - or any of the chained calls. This runs fine:
var expect = require('chai').expect;
var sinon =require('sinon');
describe('example test', () => {
it('should evaluate sinon.assert.calledWith', () => {
const stub = sinon.stub();
const call1 = stub.onCall(0).resolves(true) // don't use `.stub`;
const itemToEval = (option) => {
return stub(option);
};
return itemToEval(1).then(data => {
expect(data).to.equal(true); //passes
sinon.assert.calledWith(call1, 1); // passes
sinon.assert.calledWith(stub, 1); // passes
});
});
});
Most helpful comment
You are using the
.stubproperty. That is an internal detail of Sinon. The stub we talk about is the one returned from thestub()method - or any of the chained calls. This runs fine: