Property
Enables easy access to properties of the value of a given Answerable.
Examples:
Example API response
interface EnvironmentDetails {
name: string;
url: string;
}
interface EnvironmentsResponse {
environments: EnvironmentDetails[];
}
const response: EnvironmentsResponse = {
"environments": [
{
"name": "dev",
"url": "https://dev.example.com"
},
{
"name": "sit",
"url": "https://sit.example.com"
}
]
}
Combining Property.of and Property.at
import { actorCalled, List, Property } from '@serenity-js/core';
import { Ensure, equals } from '@serenity-js/assertions';
actorCalled('Lisa').attemptsTo(
Ensure.that(
Property.of(
List.of(response.environments)
.where(Property.at<EnvironmentDetails>().name, equals('dev'))
.first(),
).url,
equals('https://dev.example.com')
)
)
Static Method Summary
Static Public Methods | ||
public static |
Generates a Proxy around a given Answerable |
|
public static |
Static Public Methods
public static at(): Proxy<Subject> source
Generates a Proxy around a given Answerable subject
to turn any of its properties into MetaQuestions
to be used when filtering a List,
Examples:
Reading a property
import { actorCalled, Property } from '@serenity-js/core';
import { Ensure, equals } from '@serenity-js/assertions';
actorCalled('Lisa').attemptsTo(
Ensure.that(
List.of(response.environments)
.where(Property.at<EnvironmentDetails>().name, equals('dev'))
.first(),
equals(response.environments[0])
)
)
public static of(subject: Answerable<Subject>): Proxy<Subject> source
Generates a Proxy around a given Answerable subject
to turn the properties of the value it will resolve to into Questions.
Params:
Name | Type | Attribute | Description |
subject | Answerable<Subject> |
Examples:
Reading a property
import { actorCalled, Property } from '@serenity-js/core';
import { Ensure, equals } from '@serenity-js/assertions';
actorCalled('Lisa').attemptsTo(
Ensure.that(
Property.of(response).environments[0].name,
equals('dev')
)
)