Skip to main content

externalEnsure <Actual>

The interaction to Ensure verifies if the resolved value of the provided Answerable meets the specified Expectation. If not, it throws an AssertionError.

Use Ensure to verify the state of the system under test.

Basic usage with static values

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

await actorCalled('Erica').attemptsTo(
Ensure.that('Hello world!', equals('Hello world!'))
)

Composing expectations with and

import { actorCalled } from '@serenity-js/core'
import { and, Ensure, startsWith, endsWith } from '@serenity-js/assertions'

await actorCalled('Erica').attemptsTo(
Ensure.that('Hello world!', and(startsWith('Hello'), endsWith('!'))
)

Overriding the type of Error thrown upon assertion failure

import { actorCalled, TestCompromisedError } from '@serenity-js/core'
import { and, Ensure, startsWith, endsWith } from '@serenity-js/assertions'
import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'

await actorCalled('Erica')
.whoCan(CallAnApi.at('https://example.com'))
.attemptsTo(
Send.a(GetRequest.to('/api/health')),
Ensure.that(LastResponse.status(), equals(200))
.otherwiseFailWith(TestCompromisedError, 'The server is down, please cheer it up!')
)

Hierarchy

Index

Methods

staticexternalthat

staticexternaleventually

  • Creates an interaction to EnsureEventually, which verifies if the resolved value of the provided Answerable meets the specified Expectation within the expected timeframe.

    After the first try, it waits longer and longer between checks, following a simple exponential backoff pattern (2^try * 100). So 0ms the first time, then 200ms, 400ms, 800ms, 1600ms, 3200ms and so on.

    If the expectation is not met by the time the timeout expires, the interaction throws an AssertionError.


    Type parameters

    • Actual_Type

    Parameters

    Returns EnsureEventually<Actual_Type>

externalperformAs

externalotherwiseFailWith

  • otherwiseFailWith(typeOfRuntimeError: new (message: string, cause?: Error) => RuntimeError, message?: string): Interaction
  • Overrides the default AssertionError thrown when the actual value does not meet the expectation.


    Parameters

    • externaltypeOfRuntimeError: new (message: string, cause?: Error) => RuntimeError

      A constructor function producing a subtype of RuntimeError to throw, e.g. TestCompromisedError

      • externaloptionalmessage: string

        The message explaining the failure

      Returns Interaction

    externalinstantiationLocation

    • instantiationLocation(): FileSystemLocation
    • Returns the location where this Activity was instantiated.


      Returns FileSystemLocation

    externaldescribedBy

    • Resolves the description of this object in the context of the provided actor.


      Parameters

      Returns Promise<string>

    externaltoString

    • toString(): string
    • Returns a human-readable description of this object.


      Returns string