UNPKG

@fgv/ts-utils-jest

Version:
21 lines 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.matcherName = void 0; exports.predicate = predicate; const ts_utils_1 = require("../../ts-utils"); exports.matcherName = 'toSucceedAndSatisfy'; // If the result is successful and callback does not throw, returns Success with the callback return value, or // true if the callback returns undefined // If the result is successful but the callback throws, returns Failure with the thrown error // If the result is failure, returns Success with undefined function predicate(received, cb, capture) { if (received.isSuccess()) { const cbResult = capture ? (0, ts_utils_1.captureResult)(() => cb(received.value)) : (0, ts_utils_1.succeed)(cb(received.value)); if (cbResult.isSuccess()) { return (0, ts_utils_1.succeed)(cbResult.value === true || cbResult.value === undefined); } return (0, ts_utils_1.fail)(` Callback failed with:\n ${cbResult.message}`); } return (0, ts_utils_1.succeed)(undefined); } //# sourceMappingURL=predicate.js.map