Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Nightwatchjs Nightwatch Custom Assertion Creation

From Leeroopedia
Knowledge Sources
Domains Testing, Extensibility, Assertions
Last Updated 2026-02-12 00:00 GMT

Overview

An extensibility pattern for creating domain-specific test assertions that integrate with the framework's assertion and verification system.

Description

Custom Assertion Creation allows users to define assertions beyond the built-in set. Each custom assertion implements a protocol with five methods: expected() returns the expected value, pass(value) determines if the actual value passes, value(result) extracts the actual value from a command result, command(callback) executes the browser command that retrieves the value, and failure(result) detects error conditions. Custom assertions are available on both browser.assert (fail immediately) and browser.verify (log failure, continue).

Usage

Create custom assertions for domain-specific validation that is not covered by built-in assertions. Common uses include checking specific attributes, computed styles, or application state.

Theoretical Basis

The custom assertion protocol follows a retrieve-compare-report pattern:

  1. command(callback): Execute a browser command to retrieve a value
  2. value(result): Extract the actual value from the command result
  3. expected(): Return the expected value
  4. pass(value): Compare actual to expected, return boolean
  5. failure(result): Detect error conditions (element not found, etc.)
  6. message: Human-readable description of the assertion

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment