UNPKG

@serenity-js/assertions

Version:

Serenity/JS universal assertion library supporting all types of functional tests, including both web and REST API scenarios

56 lines 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.or = or; const core_1 = require("@serenity-js/core"); /** * Creates an [expectation](https://serenity-js.org/api/core/class/Expectation/) that is met when at least one of the `expectations` is met for the given actual value. * * Use `or` to combine several expectations using logical "or", * * ## Combining several expectations * * ```ts * import { actorCalled } from '@serenity-js/core' * import { Ensure, or, startsWith } from '@serenity-js/assertions' * * await actorCalled('Ester').attemptsTo( * Ensure.that('Hello World!', or(startsWith('Hello'), startsWith('Hi'))), * ) * ``` * * @param expectations * * @group Expectations */ function or(...expectations) { return new Or(expectations); } /** * @package */ class Or extends core_1.Expectation { expectations; static Separator = ' or '; static subjectFor(expectations) { return expectations .map(expectation => expectation.toString()) .join(Or.Separator); } constructor(expectations) { super('or', Or.subjectFor(expectations), async (actor, actual) => { if (!expectations || expectations.length === 0) { throw new core_1.LogicError(`No expectations provided to or()`); } let outcome; for (const expectation of expectations) { outcome = await actor.answer(expectation.isMetFor(actual)); if (outcome instanceof core_1.ExpectationMet) { return outcome; } } return new core_1.ExpectationNotMet(Or.subjectFor(expectations), outcome.expectation, outcome.expected, outcome.actual); }); this.expectations = expectations; } } //# sourceMappingURL=or.js.map