I've updated the version of chai in my project and after updating it to 3.5.0
, some tests are failing. I see that I'm not able to test arguments of the function for which I did spy.
I created a fiddle to reproduce my issue with 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 can we test argument in newer version chai.js?
As you are using Sinon, you can either use the Sinon spy methods and check the results with Chai:
expect(spy.calledWith(5)).to.equal(true);
Or you can use sinon-chai which will let you do:
expect(spy).to.have.been.calledWith(5);
See a JSFiddle of the first example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With