UNPKG

chai-spies-augment

Version:

Additions to chai-spies, adding utilities to inspect args and check if a spy was called with a partial object

51 lines (42 loc) 1.33 kB
'use strict'; 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 () { var calls = this.__spy.calls; if (calls.length > 0) { return this.argsFor(calls.length - 1); } else { throw new Error('ERROR::spy.args: Spy has not been called'); } }; /** * Returns array of arguments from specified call on spy * @param callIdx {number} */ spy.argsFor = function (callIdx) { var calls = this.__spy.calls; if (calls[callIdx]) { return calls[callIdx]; } else { throw new Error('ERROR::spy.argsFor: Invalid call index for spy'); } }; 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 }; }