UNPKG

@serenity-js/assertions

Version:

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

51 lines 1.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.not = not; const core_1 = require("@serenity-js/core"); /** * Produces an [expectation](https://serenity-js.org/api/core/class/Expectation/) that negates the provided `expectation`. * * ## Ensuring that the actual value does not equal the expected value * * ```ts * import { actorCalled } from '@serenity-js/core' * import { Ensure, equals, not } from '@serenity-js/assertions' * * const actual = { name: 'apples' } * const expected = { name: 'bananas' } * * await actorCalled('Ester').attemptsTo( * Ensure.that(actual, not(equals(expected))), * ) * ``` * * @param expectation * * @group Expectations */ function not(expectation) { return new Not(expectation); } /** * @package */ class Not extends core_1.Expectation { expectation; static flipped(message) { return message.startsWith('not ') ? message.slice(4) : `not ${message}`; } constructor(expectation) { super('not', Not.flipped(expectation.toString()), async (actor, actual) => { const subject = Not.flipped(expectation.toString()); const outcome = await actor.answer(expectation.isMetFor(actual)); const expectationDetails = core_1.ExpectationDetails.of('not', outcome.expectation); return outcome instanceof core_1.ExpectationNotMet ? new core_1.ExpectationMet(subject, expectationDetails, outcome.expected, outcome.actual) : new core_1.ExpectationNotMet(subject, expectationDetails, outcome.expected, outcome.actual); }); this.expectation = expectation; } } //# sourceMappingURL=not.js.map