Skip to main content

externalEnsureEventually <Actual>

experimental

The interaction to EnsureEventually verifies if the resolved value of the provided Answerable meets the specified Expectation within the expected timeframe.

If the expectation is not met by the time the timeout expires, the interaction throws an AssertionError. EnsureEventually retries the evaluation if resolving the actual results in an ListItemNotFoundError, but rethrows any other errors.

Use the factory method

Use the factory method [Ensure.eventually](/api/assertions/class/Ensure/#eventually] to instantiate this interaction.

Basic usage with dynamic values

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

await actorCalled('Erica').attemptsTo(
Ensure.eventually(
Text.of(PageElement.located(By.css('h1'))),
equals('Learn Serenity/JS!')
)
)

Composing expectations with and

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

await actorCalled('Erica').attemptsTo(
Ensure.eventually(
Text.of(PageElement.located(By.css('h1'))),
and(startsWith('Serenity'), endsWith('!'))
)
)

Overriding the type of Error thrown upon assertion failure

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

await actorCalled('Erica').attemptsTo(
Ensure.eventually(
Text.of(PageElement.located(By.css('h1'))),
and(startsWith('Serenity'), endsWith('!'))
).otherwiseFailWith(LogicError, `Looks like we're not on the right page`)
)

Hierarchy

Index

Constructors

externalconstructor

  • Type parameters

    • Actual

    Parameters

    Returns EnsureEventually<Actual>

Methods

externaltimeoutAfter

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