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

Question

Enables the Actor to query the system under test.

Direct Subclasses:

Examples:

A basic Question
import { Actor, AnswersQuestions, UsesAbilities, Question } from '@serenity-js/core'
import { Ensure, equals } from '@serenity-js/assertions'

const LastItemOf = <T>(list: T[]): Question<T> =>
    Question.about('last item from the list', (actor: AnswersQuestions & UsesAbilities) => {
        return list[list.length - 1];
    });

Actor.named('Quentin').attemptsTo(
    Ensure.that(LastItemFrom([1,2,3]), equals(3)),
);
A question using the Actor's Ability to do something
import { AnswersQuestions, UsesAbilities, Question } from '@serenity-js/core'
import { CallAnApi } from '@serenity-js/rest'

const TextOfLastResponseStatus = () =>
    Question.about<number>(`the text of the last response status`, actor => {
        return CallAnApi.as(actor).mapLastResponse(response => response.statusText);
    });
Mapping answers to other questions
import { Actor, AnswersQuestions, UsesAbilities, Question } from '@serenity-js/core'
import { CallAnApi, LastResponse } from '@serenity-js/rest'
import { Ensure, equals } from '@serenity-js/assertions';

const RequestWasSuccessful = () =>
    Question.about<number>(`the text of the last response status`, actor => {
        return LastResponse.status().answeredBy(actor) === 200;
    });

const actor = Actor.named('Quentin').whoCan(CallAnApi.at('https://myapp.com/api'));

actor.attemptsTo(
    Send.a(GetRequest.to('/books/0-688-00230-7')),
    Ensure.that(RequestWasSuccessful(), isTrue()),
);

Static Method Summary

Static Public Methods
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.

Static Public Methods

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

Factory method that simplifies the process of defining custom questions.

Params:

NameTypeAttributeDescription
description string
body function(actor: AnswersQuestions & UsesAbilities): R

Returns:

Question<R>

Examples:

 const EnvVariable = (name: string) =>
     Question.about(`the ${ name } env variable`, actor => process.env[name])

public static isAQuestion(maybeQuestion: any): boolean source

Checks if the value is a Question.

Params:

NameTypeAttributeDescription
maybeQuestion any

Returns:

boolean