chai-spies-augment
Version:
Additions to chai-spies, adding utilities to inspect args and check if a spy was called with a partial object
41 lines (32 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function () {
var originalSpy = _chai2.default.spy;
_chai2.default.spy = function (name, fn) {
var spy = originalSpy(name, fn);
/**
* Returns array of arguments from spy's most recent call
*/
spy.args = function () {
return this.argsFor(this.__spy.calls.length - 1);
};
/**
* Returns array of arguments from specified call on spy
* @param callIdx {number}
*/
spy.argsFor = function (callIdx) {
return this.__spy.calls[callIdx];
};
return spy;
};
// Add all the property functions back on to chai.spy object
// Code above will have removed things like chai.spy.on, chai.spy.sandbox, etc.
for (var key in originalSpy) {
_chai2.default.spy[key] = originalSpy[key];
}
};
var _chai = require('chai');
var _chai2 = _interopRequireDefault(_chai);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }