UNPKG

@serenity-js/assertions

Version:

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

31 lines 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.contain = void 0; const core_1 = require("@serenity-js/core"); const objects_1 = require("tiny-types/lib/objects"); /** * Produces an [expectation](https://serenity-js.org/api/core/class/Expectation/) that is met when the actual array of `Item[]` contains * at least one `Item` that is equal to the resolved value of `expected`. * * Note that the equality check performs comparison **by value** * using [TinyTypes `equal`](https://github.com/jan-molak/tiny-types/blob/master/src/objects/equal.ts). * * ## Ensuring that the array contains the given item * * ```ts * import { actorCalled } from '@serenity-js/core' * import { Ensure, and, startsWith, endsWith } from '@serenity-js/assertions' * * const items = [ { name: 'apples' }, { name: 'bananas' } ] * * await actorCalled('Ester').attemptsTo( * Ensure.that(items, contain({ name: 'bananas' })), * ) * ``` * * @param expected * * @group Expectations */ exports.contain = core_1.Expectation.define('contain', 'contain', (actual, expected) => actual.some(item => (0, objects_1.equal)(item, expected))); //# sourceMappingURL=contain.js.map