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

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