abstractQuestion <T>
Hierarchy
- Question
Index
Constructors
constructor
Type parameters
- T
Returns Question<T>
Methods
staticabout
Factory method that simplifies the process of defining custom questions.
Defining a custom question
import { Question } from '@serenity-js/core'
const EnvVariable = (name: string) =>
Question.about(`the ${ name } env variable`, actor => process.env[name])Type parameters
- Answer_Type
- Supported_Context_Type
Parameters
description: string
body: (actor: AnswersQuestions & UsesAbilities) => Answer_Type | Promise<Answer_Type>
optionalmetaQuestionBody: (answerable: Answerable<Supported_Context_Type>) => Question<Promise<Answer_Type>> | Question<Answer_Type>
Returns MetaQuestionAdapter<Supported_Context_Type, Awaited<Answer_Type>>
staticfromObject
Generates a QuestionAdapter that recursively resolves any Answerable fields of the provided object, including Answerable fields of nested objects.
Optionally, the method accepts
overrides
to be shallow-merged with the fields of the originalsource
, producing a new merged object.Overrides are applied from left to right, with subsequent objects overwriting property assignments of the previous ones.
Resolving an object recursively using
Question.fromObject
import { actorCalled, Question } from '@serenity-js/core'
import { Send, PostRequest } from '@serenity-js/rest'
import { By, Text, PageElement } from '@serenity-js/web'
await actorCalled('Daisy')
.whoCan(CallAnApi.at('https://api.example.org'))
.attemptsTo(
Send.a(
PostRequest.to('/products/2')
.with(
Question.fromObject({
name: Text.of(PageElement.located(By.css('.name'))),
})
)
)
);Merging objects using
Question.fromObject
import { actorCalled, Question } from '@serenity-js/core'
import { Send, PostRequest } from '@serenity-js/rest'
import { By, Text, PageElement } from '@serenity-js/web'
await actorCalled('Daisy')
.whoCan(CallAnApi.at('https://api.example.org'))
.attemptsTo(
Send.a(
PostRequest.to('/products/2')
.with(
Question.fromObject({
name: Text.of(PageElement.located(By.css('.name'))),
quantity: undefined,
}, {
quantity: 2,
})
)
)
);Learn more
Type parameters
- Source_Type: object
Parameters
source: Answerable<WithAnswerableProperties<Source_Type>>
rest...overrides: Answerable<Partial<WithAnswerableProperties<Source_Type>>>[]
Returns QuestionAdapter<RecursivelyAnswered<Source_Type>>
staticisAQuestion
staticisAMetaQuestion
Checks if the value is a MetaQuestion.
Type parameters
- CT
- RQT: Question<unknown>
Parameters
maybeMetaQuestion: unknown
The value to check
Returns maybeMetaQuestion is MetaQuestion<CT, RQT>
abstracttoString
Returns the description of the subject of this Question.
Returns string
abstractdescribedAs
Changes the description of this question’s subject.
Parameters
subject: string
Returns Question<T>
abstractansweredBy
Parameters
actor: AnswersQuestions & UsesAbilities
Returns T
publicas
Maps this question to one of a different type.
Question.about('number returned as string', actor => '42') // returns: QuestionAdapter<string>
.as(Number) // returns: QuestionAdapter<number>Type parameters
- O
Parameters
mapping: (answer: Awaited<T>) => O | Promise<O>
Returns QuestionAdapter<O>
Questions describe how actors should query the system under test or the test environment to retrieve some information.
Questions are the core building block of the Screenplay Pattern, along with Actors, Abilities, Interactions, and Tasks.
Learn more about:
Implementing a basic custom Question
Implementing a Question that uses an Ability
Just like the interactions, a Question also can use actor’s abilities.
Here, we use the ability to CallAnApi to retrieve a property of an HTTP response.
Learn more
Mapping answers to other questions
Apart from retrieving information, questions can be used to transform information retrieved by other questions.
Here, we use the factory method Question.about to produce a question that makes the received actor answer LastResponse.status and then compare it against some expected value.
Note that the above example is for demonstration purposes only, Serenity/JS provides an easier way to verify the response status of the LastResponse: