@serenity-js/assertions
Version:
Serenity/JS universal assertion library supporting all types of functional tests, including both web and REST API scenarios
98 lines • 4.12 kB
TypeScript
import type { Answerable, AnswersQuestions, CollectsArtifacts, Expectation, RuntimeError, UsesAbilities } from '@serenity-js/core';
import { Duration, Interaction } from '@serenity-js/core';
import type { FileSystemLocation } from '@serenity-js/core/lib/io';
/**
* The [interaction](https://serenity-js.org/api/core/class/Interaction/) to `EnsureEventually`
* verifies if the resolved value of the provided [`Answerable`](https://serenity-js.org/api/core/#Answerable)
* meets the specified [`Expectation`](https://serenity-js.org/api/core/class/Expectation/) within the expected timeframe.
*
* If the expectation is not met by the time the timeout expires, the interaction throws an [`AssertionError`](https://serenity-js.org/api/core/class/AssertionError/).
* `EnsureEventually` retries the evaluation if resolving the `actual` results in an [`ListItemNotFoundError`](https://serenity-js.org/api/core/class/ListItemNotFoundError/),
* but rethrows any other errors.
*
* :::tip Use the factory method
* Use the factory method [`Ensure.eventually`](https://serenity-js.org/api/assertions/class/Ensure/#eventually) to instantiate this interaction.
* :::
*
* ## Basic usage with dynamic values
* ```ts
* 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`
*
* ```ts
* 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
*
* ```ts
* 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`)
* )
* ```
*
* @experimental
*
* @group Activities
*/
export declare class EnsureEventually<Actual> extends Interaction {
protected readonly actual: Answerable<Actual>;
protected readonly expectation: Expectation<Actual>;
protected readonly timeout?: Duration;
/**
* @param actual
* @param expectation
* @param location
* @param timeout
*/
constructor(actual: Answerable<Actual>, expectation: Expectation<Actual>, location: FileSystemLocation, timeout?: Duration);
/**
* Override the default timeout set via [`SerenityConfig.interactionTimeout`](https://serenity-js.org/api/core/class/SerenityConfig/#interactionTimeout).
*
* @param timeout
*/
timeoutAfter(timeout: Duration): EnsureEventually<Actual>;
/**
* @inheritDoc
*/
performAs(actor: UsesAbilities & AnswersQuestions & CollectsArtifacts): Promise<void>;
/**
* Overrides the default [`AssertionError`](https://serenity-js.org/api/core/class/AssertionError/) thrown when
* the actual value does not meet the expectation.
*
* @param typeOfRuntimeError
* A constructor function producing a subtype of [`RuntimeError`](https://serenity-js.org/api/core/class/RuntimeError/) to throw, e.g. [`TestCompromisedError`](https://serenity-js.org/api/core/class/TestCompromisedError/)
*
* @param message
* The message explaining the failure
*/
otherwiseFailWith(typeOfRuntimeError: new (message: string, cause?: Error) => RuntimeError, message?: string): Interaction;
}
//# sourceMappingURL=EnsureEventually.d.ts.map