@serenity-js/assertions
Version:
Serenity/JS universal assertion library supporting all types of functional tests, including both web and REST API scenarios
49 lines • 1.71 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.and = and;
const core_1 = require("@serenity-js/core");
/**
* Creates an [expectation](https://serenity-js.org/api/core/class/Expectation/) that is met when all the `expectations` are met for the given actual value.
*
* Use `and` to combine several expectations using logical "and",
*
* ## Combining several expectations
*
* ```ts
* import { actorCalled } from '@serenity-js/core'
* import { Ensure, and, startsWith, endsWith } from '@serenity-js/assertions'
*
* await actorCalled('Ester').attemptsTo(
* Ensure.that('Hello World!', and(startsWith('Hello'), endsWith('!'))),
* )
* ```
*
* @param expectations
*
* @group Expectations
*/
function and(...expectations) {
return new And(expectations);
}
/**
* @package
*/
class And extends core_1.Expectation {
expectations;
static Separator = ' and ';
constructor(expectations) {
const description = expectations.map(expectation => expectation.toString()).join(And.Separator);
super('and', description, async (actor, actual) => {
let outcome;
for (const expectation of expectations) {
outcome = await actor.answer(expectation.isMetFor(actual));
if (outcome instanceof core_1.ExpectationNotMet) {
return new core_1.ExpectationNotMet(description, outcome.expectation, outcome.expected, outcome.actual);
}
}
return new core_1.ExpectationMet(description, outcome?.expectation, outcome?.expected, outcome?.actual);
});
this.expectations = expectations;
}
}
//# sourceMappingURL=and.js.map
;