@thisisagile/easy-test
Version:
Straightforward library for testing microservices built with @thisisagile/easy
30 lines • 1.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toFailWith = exports.toFail = exports.toResultWith = void 0;
const Match_1 = require("./Match");
const notDefined = 'Results is not defined.';
const doesNotFail = 'Results does not fail.';
const hasMessage = (res, message) => res.results.some((r) => r.message === message);
const messages = (res) => "'" + res?.results.map(r => r.message).join("', '") + "'";
const toResultWith = (results, message) => (0, Match_1.match)(results)
.undefined(r => r, notDefined)
.not(r => hasMessage(r, message), r => `Results does not have message '${message}', but it has messages ${messages(r)} instead.`)
.else(`Succeeds with message ${message}`);
exports.toResultWith = toResultWith;
const toFail = (results) => (0, Match_1.match)(results)
.undefined(r => r, notDefined)
.not(r => !r.isValid, doesNotFail)
.else('Results does not fail');
exports.toFail = toFail;
const toFailWith = (results, message) => (0, Match_1.match)(results)
.undefined(r => r, notDefined)
.not(r => !r.isValid, doesNotFail)
.not(r => hasMessage(r, message), r => `Fails, but results does not have message '${message}', but it has messages ${messages(r)} instead.`)
.else(`Fails with message '${message}'`);
exports.toFailWith = toFailWith;
expect.extend({
toResultWith: exports.toResultWith,
toFail: exports.toFail,
toFailWith: exports.toFailWith,
});
//# sourceMappingURL=ResultMatchers.js.map