liveBook · Manning

Component testing

As explained in BDD in Action, Second Edition

A component test evaluates an individual software component or UI component in isolation from parts of the wider system.

Component testing evaluates an individual UI component in isolation from the wider system. It suits behavior that can be verified without assembling every service, while keeping the test focused on the component’s visible contract. section 13.2.2 section 15.1.5

Choose the test boundary according to the behavior being verified:

  • Test server-side email validation through API calls when the user interface adds no meaningful coverage. section 13.2.2
  • Test field validation and terms-and-conditions behavior through an isolated UI component when the concern is primarily local UI behavior. section 13.2.2 section 13.2.2
  • Use a web UI with mocked web services when the scenario needs UI interaction but not real downstream services. section 15.1.5

Mandatory registration fields

A component test can render the registration form and verify that email, password, first name, last name, address, and country are mandatory. A separate scenario can verify the displayed message when the terms and conditions remain unapproved. section 13.2.2 section 13.2.2

Listing 15.5 Implementing variations of a task interacting with different interfaces
import { Answerable, QuestionAdapter, Task } from '@serenity-js/core'
import { Send, PostRequest } from '@serenity-js/rest'
import { Ensure, equals } from '@serenity-js/assertions'
 
class SignUp {
  using =(travelerDetails: QuestionAdapter<TravelerDetails>) =>
    Task.where(`#actor signs up`,
      LocateRegistrationForm(),
      FillOutRegistrationForm.using(travelerDetails),
      SubmitRegistrationForm(),
    )
 
  viaApiUsing = (travelerDetails: QuestionAdapter<TravelerDetails>) =>
    Task.where(`#actor signs up (via API)`,
      Send.a(PostRequest.to('/api/auth/register')
          .with(travelerDetails)),
      Ensure.that(LastResponse.status(), equals(201)),
    )
}

Compare a UI task with its API-backed variation to keep setup efficient while preserving the same business-level registration behavior. section 15.1.5

How BDD in Action, Second Edition covers it

How deep it goes
Explains isolation and test-boundary choices with registration scenarios, but stops short of detailed component-test implementation.
Examples
Uses registration-field validation, terms acceptance, mocked services, Storybook, and Playwright Component Tests as examples.
What it assumes
Assumes distinguishable UI and API responsibilities, while treating requirements and acceptance scenarios as the starting point.
What you can do after
Apply it via Storybook or Playwright Component Tests to verify UI behavior without deploying the entire system.
How it connects
Connects component testing with UI testing, API testing, acceptance testing, mock web services, and blended testing.

Also explained in

Compare how 3 books explain component testing →

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.