To.have.been.calledWith is not a functional bug in chai # 3.5.0
I have updated the chai version in my project and after updating to 3.5.0
some tests do not work. I see that I cannot validate the arguments of the function I am spy on.
I created a script to reproduce my problem using the sample method here - JSFiddle
describe('Mocha + Chai JsFiddle', function() {
it('should test arg', function() {
var spy = sinon.spy(test, 'testFun');
test.testFun(5);
expect(spy).to.have.been.called.with(5);
});
});
Can anyone suggest how we can test the argument in a newer version of chai.js?
source to share
When using Sinon, you can use Sinon's spy methods and check the results with Chai:
expect(spy.calledWith(5)).to.equal(true);
Or you can use sinon-chai , which will allow you to do:
expect(spy).to.have.been.calledWith(5);
source to share
Perhaps you forgot to include sinon-chai.js? Here is a working fiddle https://jsfiddle.net/zjet0432/1/
I only added sinon-chai.js and changed your last line toexpect(spy).to.have.been.calledWith(5);
source to share