Principle:Nightwatchjs Nightwatch Component Test Authoring
| Knowledge Sources | |
|---|---|
| Domains | Testing, Component_Testing |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
A testing pattern for mounting and verifying individual UI components in isolation using a global element API for element initialization and interaction.
Description
Component Test Authoring focuses on testing a single component by mounting it in a browser with controlled props and state. Unlike E2E tests that navigate to full pages, component tests render an isolated component and verify its behavior. The element() global utility creates element references before tests begin, which can then be used for interactions and assertions.
The pattern combines component rendering with Nightwatch's assertion capabilities, allowing the same expect/assert API used for E2E tests to be applied to individual components.
Usage
Use this principle when testing component behavior, props, state transitions, user interactions, and rendering output in isolation from the rest of the application.
Theoretical Basis
Component testing follows the isolation testing principle:
- Mount a single component with specific props/state
- Initialize element references using the global element() utility
- Interact with the component (click, type, etc.)
- Assert component output matches expectations