UNPKG

@thisisagile/easy-test

Version:

Straightforward library for testing microservices built with @thisisagile/easy

44 lines (42 loc) 1.61 kB
import { isDefined } from "./chunk-O475TEG2.mjs"; // src/matchers/Check.ts var Check = class _Check { constructor(ctx, received, expected, failed = false, message = "") { this.ctx = ctx; this.received = received; this.expected = expected; this.failed = failed; this.message = message; } print(message) { return (typeof message === "function" ? message([this.received, this.expected]) : message).replace("{r}", this.ctx.utils.printReceived(this.received)).replace("{e}", this.ctx.utils.printExpected(this.expected)).replace("{diff}", this.ctx.utils.diff(this.received, this.expected) ?? ""); } not(p, message) { if (this.failed) { return this; } try { return new _Check(this.ctx, this.received, this.expected, !p([this.received, this.expected]), this.print(message)); } catch (e) { return new _Check(this.ctx, this.received, this.expected, true, e.message); } } undefined(p, message) { return this.not(() => isDefined(p([this.received, this.expected])), this.print(message)); } else(message = "Expected {r} not to match with {e}, but it did.") { return { pass: !this.failed, message: () => this.failed ? this.message : this.print(message) }; } }; var check = (ctx, received, expected) => new Check(ctx, received, expected); var checkDefined = (ctx, received, expected) => new Check(ctx, received, expected).undefined(([r]) => r, "Received array is undefined.").undefined(([, e]) => e, "Expected array is undefined."); export { check, checkDefined }; //# sourceMappingURL=chunk-Z4XAP66Q.mjs.map