UNPKG

@thisisagile/easy-test

Version:

Straightforward library for testing microservices built with @thisisagile/easy

36 lines 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.match = exports.Match = void 0; const Utils_1 = require("../utils/Utils"); const Types_1 = require("../utils/Types"); class Match { constructor(subject, failed = false, message = '') { this.subject = subject; this.failed = failed; this.message = message; } not(p, message) { if (this.failed) { return this; } try { return new Match(this.subject, !p(this.subject), (0, Types_1.toMessage)(message, this.subject)); } catch (e) { return new Match(this.subject, true, e.message); } } undefined(p, message) { return this.not(() => (0, Utils_1.isDefined)(p(this.subject)), message); } else(message) { return { pass: !this.failed, message: () => (this.failed ? (0, Types_1.toMessage)(this.message) : `${(0, Types_1.toMessage)(message, this.subject)}, which we did not expect.`), }; } } exports.Match = Match; const match = (subject) => new Match(subject); exports.match = match; //# sourceMappingURL=Match.js.map