earljs
Version:
Ergonomic, modern and type-safe assertion library
28 lines (27 loc) • 1.24 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.toHaveBeenCalledWith = void 0;
const format_1 = require("../../format");
const isEqual_1 = require("../../isEqual");
function toHaveBeenCalledWith(control, expectedArgs) {
for (const call of control.actual.calls) {
if ((0, isEqual_1.isEqual)(call.args, expectedArgs)) {
return control.assert({
success: true,
reason: '-',
negatedReason: `Mock was called with ${(0, format_1.formatCompact)(expectedArgs)} but wasn't expected to`,
actual: (0, format_1.format)(call.args, null),
expected: (0, format_1.format)(expectedArgs, call.args),
});
}
}
// @todo this should find smallest diff between expected calls and actual calls
return control.assert({
success: false,
reason: `Mock was not called with ${(0, format_1.formatCompact)(expectedArgs)} but was expected to`,
negatedReason: '-',
actual: (0, format_1.format)(control.actual.calls[0], null),
expected: (0, format_1.format)(expectedArgs, control.actual.calls[0]),
});
}
exports.toHaveBeenCalledWith = toHaveBeenCalledWith;
;