liveBook · Manning

Expectation

As explained in BDD in Action, Second Edition

An expectation is a declarative condition that evaluates whether an observed value or state satisfies a specified criterion.

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

How BDD in Action, Second Edition covers it

How deep it goes
Combines presence, content, status, synchronization, and dismissal checks, while deferring the internal implementation of reusable tasks.
Examples
Uses a temporary duplicate-email toaster, expected message text, success or error status, and reusable submission-verification tasks.
What it assumes
Assumes familiarity with Cucumber step definitions, actors, page elements, and low-level web interactions.
What you can do after
Apply it via Serenity/JS to express readable, reusable checks for interface messages and submission outcomes.
How it connects
Connects Serenity/JS Assertions, Wait.until, Ensure.that, Cucumber step definitions, page elements, and reusable Tasks.

Also explained in

Compare how 5 books explain expectation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of BDD in Action, Second Edition. The section links point to the parts of the book it draws on.