An expectation is a declarative condition used to determine whether an observed value or interface state meets a required criterion. In Serenity/JS, assertions such as Ensure.that verify a message, while Wait.until synchronizes evaluation with its appearance or disappearance. section 15.1.7
Verifying a duplicate-email error
A verification task waits for a toaster message, checks that its text includes “Email exists,” dismisses it, and waits for it to disappear. The low-level checks can be composed as VerifySubmission.failedWith(expectedMessage), keeping the step readable and reusable. section 15.1.7
import { Actor, Wait } from '@serenity-js/core'
import { Click } from '@serenity-js/web'
import { Ensure, includes, isPresent, not } from '@serenity-js/assertions'
Then('{pronoun} should be advised of an error: {string}',
(actor: Actor, expectedMessage: string) =>
actor.attemptsTo(
// wait for the message to appear
Wait.until(ToasterMessage(), isPresent()),
// verify the message
Ensure.that(Text.of(ToasterMessage()), includes(expectedMessage)),
// dismiss the message
Click.on(ToasterMessage()),
// wait for the message to disappear
Wait.until(ToasterMessage(), not(isPresent())),
)
)
Inspect the complete Serenity/JS interaction sequence implementing presence, message-content, dismissal, and disappearance expectations. section 15.1.7




