Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

to.have.been.calledWith is not a function error in chai#3.5.0

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?

like image 818
Jay Shukla Avatar asked May 16 '17 08:05

Jay Shukla


1 Answers

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

like image 197
James Monger Avatar answered Oct 16 '22 16:10

James Monger