import {Expectation} from '@serenity-js/core/lib/screenplay/questions'
public class | source

Expectation

Defines an expectation to be used with assertions and Questions like List.

Extends:

Question → Expectation

Direct Subclasses:

src/screenplay/questions/Expectation.ts~DynamicallyGeneratedExpectation, src/screenplay/questions/Expectation.ts~ExpectationAlias

Tests:

Static Method Summary

Static Public Methods
public static

thatActualShould(relationshipName: string, expectedValue: Answerable<E>): function(predicate: Predicate<A, E>): Expectation<E, A>

Used to define a simple Expectation

public static

to(relationshipName: string): function(...expectations: Array<Expectation<any, A>>): Expectation<any, A>

Used to compose Expectations.

Inherited Summary

From class Question
public static

about(description: string, body: function(actor: AnswersQuestions & UsesAbilities): R): Question<R>

Factory method that simplifies the process of defining custom questions.

public static

isAQuestion(maybeQuestion: any): boolean

Checks if the value is a Question.

public

subject: *

public

describedAs(subject: string): Question<T>

Changes the description of this question's subject.

public

map(mapping: function(value: A, index?: number): Promise<O> | O): Question<Promise<Mapped>>

Creates a new Question, which value is a result of applying the mapping function to the value of this Question.

public

toString(): string

Describes the subject of this Question.

Static Public Methods

public static thatActualShould(relationshipName: string, expectedValue: Answerable<E>): function(predicate: Predicate<A, E>): Expectation<E, A> source

Used to define a simple Expectation

Params:

NameTypeAttributeDescription
relationshipName string
expectedValue Answerable<E>

Returns:

function(predicate: Predicate<A, E>): Expectation<E, A>

Examples:

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

 function isDivisibleBy(expected: Answerable<number>): Expectation<number> {
     return Expectation.thatActualShould<number, number>('have value divisible by', expected)
         .soThat((actualValue, expectedValue) => actualValue % expectedValue === 0);
 }

 actorCalled('Erica').attemptsTo(
     Ensure.that(4, isDivisibleBy(2)),
 );

public static to(relationshipName: string): function(...expectations: Array<Expectation<any, A>>): Expectation<any, A> source

Used to compose Expectations.

Params:

NameTypeAttributeDescription
relationshipName string

Returns:

function(...expectations: Array<Expectation<any, A>>): Expectation<any, A>

Examples:

 import { actorCalled, Expectation } from '@serenity-js/core';
 import { Ensure, and, or, isGreaterThan, isLessThan, equals  } from '@serenity-js/assertions';

 function isWithin(lowerBound: number, upperBound: number) {
     return Expectation
         .to(`have value within ${ lowerBound } and ${ upperBound }`)
         .soThatActual(and(
             or(isGreaterThan(lowerBound), equals(lowerBound)),
             or(isLessThan(upperBound), equals(upperBound)),
         ));
 }

 actorCalled('Erica').attemptsTo(
     Ensure.that(5, isWithin(3, 6)),
 );