Skip to main content

externalproperty

Callable

  • property<Actual, PropertyName>(propertyName: PropertyName, expectation: Expectation<Actual[PropertyName]>): Expectation<Actual>

  • Creates an expectation that is met when the value of the actual[propertyName] meets the expectation.

    Ensuring that an array has an item

    import { actorCalled } from '@serenity-js/core'
    import { Ensure, property } from '@serenity-js/assertions'

    const list = [ 'hello', 'world' ]

    await actorCalled('Ester').attemptsTo(
    Ensure.that(list, property(0, isPresent())),
    )

    Ensuring that the property meets an expectation

    import { actorCalled } from '@serenity-js/core'
    import { Ensure, property, equals } from '@serenity-js/assertions'

    const list = [ 'hello', 'world' ]

    await actorCalled('Ester').attemptsTo(
    Ensure.that(list, property('length', equals(2))),
    )

    Asserting on a list of objects

    import { actorCalled } from '@serenity-js/core'
    import { Ensure, property, equals } from '@serenity-js/assertions'

    const developers = [{
    name: 'Jan',
    id: '@jan-molak',
    }, {
    name: 'John',
    id: '@wakaleo',
    }]

    await actorCalled('Ester').attemptsTo(
    Ensure.that(
    developers,
    containItemsWhereEachItem(
    property('id', startsWith('@'))
    ),
    ),
    )

    Type parameters

    • Actual: object
    • PropertyName: string | number | symbol

    Parameters

    • externalpropertyName: PropertyName
    • externalexpectation: Expectation<Actual[PropertyName]>

    Returns Expectation<Actual>