Skip to main content

EnsureEventually <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 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

  • Interaction
    • EnsureEventually

Index

Constructors

constructor

  • new EnsureEventually<Actual>(actual: Answerable<Actual>, expectation: Expectation<Actual>, location: FileSystemLocation, timeout?: Duration): EnsureEventually<Actual>
  • Type parameters

    • Actual

    Parameters

    • actual: Answerable<Actual>
    • expectation: Expectation<Actual>
    • location: FileSystemLocation
    • optionaltimeout: Duration

    Returns EnsureEventually<Actual>

Methods

timeoutAfter

performAs

  • performAs(actor: UsesAbilities & AnswersQuestions & CollectsArtifacts): Promise<void>
  • @inheritDoc

    Parameters

    • actor: UsesAbilities & AnswersQuestions & CollectsArtifacts

    Returns Promise<void>

otherwiseFailWith

  • 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

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

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

    • optionalmessage: string

      The message explaining the failure

    Returns Interaction

instantiationLocation

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


    Returns FileSystemLocation

toString

  • toString(): string
  • Generates a human-friendly description to be used when reporting this Activity.

    Note: When this activity is reported, token #actor in the description will be replaced with the name of the actor performing this Activity.

    For example, #actor clicks on a button becomes Wendy clicks on a button.


    Returns string