3

I am trying to test my node.js code using Mocha, Sinon, and chai.

var callback = function (err, resultSet) {
    should.exist(resultSet);
    stubbedExecuteSqlQuery.should.be.called;
    done();
};
stubbedExecuteSqlQuery.yields(null, expectedResultSet);
db.getResults(param1,param2, user, callback);

when the above code gets executed, it throws an error :

Invalid Chai property: called. Did you mean "all"?

The code used to work fine on chai version ^3.5.0 but after my recent package upgrade to ^4.1.2 the code has stopped working and has started throwing such errors.

I tried searching for it on the internet but could not find any useful information.

Any help will be appreciated. Thanks in advance!

writeToBhuwan
  • 3,233
  • 11
  • 39
  • 67
  • 2
    According to Chai's current documentation, the syntax should be the following : `spy.should.have.been.called()`. Also you should take a look at the breaking changes of the different versions that you've skipped : http://www.chaijs.com/releases/ – boehm_s Jun 25 '18 at 13:51
  • 2
    Does this answer your question? [Invalid Chai property when calling calledOnce](https://stackoverflow.com/questions/45314317/invalid-chai-property-when-calling-calledonce) – Sanderfish Jun 24 '21 at 19:07

1 Answers1

0

I had a similar issue, I think it had something to do with using .yields I ended up using .calledOnce . Try the following:

assert(stubbedExecuteSqlQuery.calledOnce);

The upside with this is that if needed you can do .calledTwice etc..