UNPKG

aws-sdk-client-mock-jest

Version:
80 lines 5.2 kB
import { __assign, __spreadArray } from "tslib"; import { expect } from 'expect'; import { createBaseMatchers } from './jestMatchers'; /** * Prettyprints command calls for message */ function addCalls(ctxUtils, calls) { var msgs = []; for (var _i = 2; _i < arguments.length; _i++) { msgs[_i - 2] = arguments[_i]; } if (calls.length === 0) return msgs.join('\n'); return __spreadArray(__spreadArray(__spreadArray([], msgs, true), [ '', 'Calls:' ], false), calls.map(function (c, i) { return " ".concat(i + 1, ". ").concat(c.args[0].constructor.name, ": ").concat(ctxUtils.printReceived(c.args[0].input)); }), true).join('\n'); } var baseMatchers = createBaseMatchers({ toHaveReceivedCommand: function (_a) { var client = _a.client, cmd = _a.cmd, notPrefix = _a.notPrefix, calls = _a.calls, commandCalls = _a.commandCalls, ctxUtils = _a.ctxUtils; return addCalls(ctxUtils, calls, "Expected ".concat(client, " to ").concat(notPrefix, "receive ").concat(ctxUtils.printExpected(cmd)), "".concat(client, " received ").concat(ctxUtils.printExpected(cmd), " ").concat(ctxUtils.printReceived(commandCalls.length), " times")); }, toHaveReceivedCommandTimes: function (expectedCalls) { return function (_a) { var calls = _a.calls, client = _a.client, cmd = _a.cmd, commandCalls = _a.commandCalls, notPrefix = _a.notPrefix, ctxUtils = _a.ctxUtils; return addCalls(ctxUtils, calls, "Expected ".concat(client, " to ").concat(notPrefix, "receive ").concat(ctxUtils.printExpected(cmd), " ").concat(ctxUtils.printExpected(expectedCalls), " times"), "".concat(client, " received ").concat(ctxUtils.printExpected(cmd), " ").concat(ctxUtils.printReceived(commandCalls.length), " times")); }; }, toHaveReceivedCommandWith: function (input) { return function (_a) { var client = _a.client, cmd = _a.cmd, notPrefix = _a.notPrefix, data = _a.data, calls = _a.calls, ctxUtils = _a.ctxUtils; return addCalls(ctxUtils, calls, "Expected ".concat(client, " to ").concat(notPrefix, "receive ").concat(ctxUtils.printExpected(cmd), " with ").concat(ctxUtils.printExpected(input)), "".concat(client, " received matching ").concat(ctxUtils.printExpected(cmd), " ").concat(ctxUtils.printReceived(data.matchCount), " times")); }; }, toHaveReceivedNthCommandWith: function (call, input) { return function (_a) { var cmd = _a.cmd, client = _a.client, data = _a.data, notPrefix = _a.notPrefix, ctxUtils = _a.ctxUtils, calls = _a.calls; return addCalls.apply(void 0, __spreadArray([ctxUtils, calls, "Expected ".concat(client, " to ").concat(notPrefix, "receive ").concat(call, ". ").concat(ctxUtils.printExpected(cmd), " with ").concat(ctxUtils.printExpected(input))], (data.received ? [ "".concat(client, " received ").concat(ctxUtils.printReceived(data.received.constructor.name), " with input:"), ctxUtils.printDiffOrStringify(input, data.received.input, 'Expected', 'Received', false), ] : []), false)); }; }, toHaveReceivedNthSpecificCommandWith: function (call, input) { return function (_a) { var cmd = _a.cmd, client = _a.client, data = _a.data, notPrefix = _a.notPrefix, ctxUtils = _a.ctxUtils, calls = _a.calls; return addCalls.apply(void 0, __spreadArray([ctxUtils, calls, "Expected ".concat(client, " to ").concat(notPrefix, "receive ").concat(call, ". ").concat(ctxUtils.printExpected(cmd), " with ").concat(ctxUtils.printExpected(input))], (data.received ? [ "".concat(client, " received ").concat(ctxUtils.printReceived(data.received.constructor.name), " with input:"), ctxUtils.printDiffOrStringify(input, data.received.input, 'Expected', 'Received', false), ] : []), false)); }; }, toHaveReceivedAnyCommand: function (_a) { var client = _a.client, notPrefix = _a.notPrefix, calls = _a.calls, ctxUtils = _a.ctxUtils; return addCalls(ctxUtils, calls, "Expected ".concat(client, " to ").concat(notPrefix, "receive any command"), "".concat(client, " received any command ").concat(ctxUtils.printReceived(calls.length), " times")); }, }, function (sample) { return expect.objectContaining(sample); }); /* typing ensures keys matching */ var aliasMatchers = { toReceiveCommandTimes: baseMatchers.toHaveReceivedCommandTimes, toReceiveCommand: baseMatchers.toHaveReceivedCommand, toReceiveCommandWith: baseMatchers.toHaveReceivedCommandWith, toReceiveNthCommandWith: baseMatchers.toHaveReceivedNthCommandWith, toReceiveNthSpecificCommandWith: baseMatchers.toHaveReceivedNthSpecificCommandWith, toReceiveAnyCommand: baseMatchers.toHaveReceivedAnyCommand, }; // Skip registration if jest expect does not exist if (typeof expect !== 'undefined' && typeof expect.extend === 'function') { expect.extend(__assign(__assign({}, baseMatchers), aliasMatchers)); } //# sourceMappingURL=jest.js.map