javascript - Invalid Chai property when calling calledOnce -
i'm having problems writing tests in javascript sinon , chai. i'm trying check if function called on spy , "error: invalid chai property: calledonce"
i'm doing same thing in project same test dependencies without problem...
var udpsocketstub = this.sandbox.spy(udpsocket, 'send'); expect(udpsocketstub).calledonce; // should fail "dependencies": { "body-parser": "~1.17.1", "bootstrap": "^4.0.0-alpha.6", "chai": "^4.1.0", "co-mocha": "^1.2.0", "cookie-parser": "~1.4.3", "debug": "~2.6.3", "express": "~4.15.2", "jquery": "^3.2.1", "mocha": "^3.4.2", "morgan": "~1.8.1", "node-compass": "0.2.3", "pug": "^2.0.0-rc.1", "serve-favicon": "~2.4.2", "sinon": "^2.3.8", "sinon-chai": "^2.12.0" }
you're missing sinon-chai
package, adds sinon-like assertions chai.
npm install --save sinon-chai
initialization:
var chai = require('chai'); var sinon = require('sinon'); chai.use(require('sinon-chai'));
in case you're wondering, using stub or original function both work:
var expect = chai.expect; var udpsocketstub = this.sandbox.spy(udpsocket, 'send'); // make call updsocket.send({..}); // both should pass expect(udpsocketstub).calledonce; expect(udpsocket.send).calledonce; // identical, more readable expect(udpsocketstub).to.have.been.calledonce; expect(udpsocket.send).to.have.been.calledonce;
Comments
Post a Comment