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.

Implementation:DevExpress Testcafe TestingUnit

From Leeroopedia
Knowledge Sources
Domains Testing, Test Structure, API Design
Principle DevExpress_Testcafe_Fixture_Declaration
Last Updated 2026-02-12 12:00 GMT

Overview

TestingUnit is the abstract base class shared by both Fixture and Test, providing the common chainable API surface for page URLs, metadata, authentication, request hooks, client scripts, and skip/only modifiers.

Description

Defined in src/api/structure/testing-unit.ts, TestingUnit extends BaseUnit (which supplies id and unitType) and centralizes all the API methods that Fixture and Test have in common. The class uses a delegated-API pattern: during construction, it creates an apiOrigin function and attaches all API methods to it via delegateAPI, enabling the familiar TestCafe chainable syntax (e.g., fixture`Name`.page`URL`.meta({...})).

Key API methods implemented as private dollar-suffixed methods (resolved by the delegation system):

  • _page$ -- Sets the page URL, validates it, and resolves it against a base URL.
  • _httpAuth$ -- Configures HTTP authentication credentials (username, password, optional domain/workstation).
  • _meta$ -- Sets metadata key-value pairs or an object of metadata.
  • _skipJsErrors$ -- Configures which JavaScript errors to skip during test execution.

Getter-style API properties:

  • _only$getter -- Marks the unit to run exclusively.
  • _skip$getter -- Marks the unit to be skipped.
  • _disablePageReloads$getter / _enablePageReloads$getter -- Toggles page reload behavior.
  • _disablePageCaching$getter -- Disables page caching.

The static method makeAPIListForChildClass is used by Fixture and Test to merge the parent API list with their own additional methods. The static init method provides a factory pattern for creating instances wrapped in the delegated API.

Usage

You do not instantiate TestingUnit directly. It is the shared superclass of Fixture and Test. Understanding this class is essential when examining how the TestCafe API chain works internally, or when extending the test structure API with new methods.

Code Reference

Source Location

Signature

export default abstract class TestingUnit extends BaseUnit {
    public readonly testFile: TestFile;
    public name: string | null;
    public disableConcurrency: boolean;
    public pageUrl: string;
    public baseUrl: string | undefined;
    public authCredentials: null | AuthCredentials;
    public meta: Metadata;
    public only: boolean;
    public skip: boolean;
    public requestHooks: RequestHook[];
    public clientScripts: ClientScriptInit[];
    public disablePageReloads: boolean | undefined;
    public disablePageCaching: boolean;
    public apiMethodWasCalled: FlagList;
    public apiOrigin: Function;
    public skipJsErrorsOptions?: boolean | SkipJsErrorsOptionsObject
        | SkipJsErrorsCallback | SkipJsErrorsCallbackWithOptionsObject;

    protected constructor (
        testFile: TestFile,
        unitType: UnitType,
        pageUrl: string,
        baseUrl?: string
    );

    protected abstract _add (...args: unknown[]): unknown;

    private _only$getter (): Function;
    private _skip$getter (): Function;
    private _disablePageReloads$getter (): Function;
    private _enablePageReloads$getter (): Function;
    private _page$ (url: string, ...rest: unknown[]): Function;
    private _skipJsErrors$ (options?: boolean | SkipJsErrorsOptionsObject
        | SkipJsErrorsCallback | SkipJsErrorsCallbackWithOptionsObject): Function;
    private _httpAuth$ (credentials: AuthCredentials): Function;
    private _meta$ (key: string | Dictionary<string>, value?: string): Function;
    private _disablePageCaching$getter (): Function;

    public static makeAPIListForChildClass (ChildClass: unknown): void;
    public static init (ChildClass: unknown, ...initProps: unknown[]): TestingUnit;
}

Import

import TestingUnit from './testing-unit';
// Internal import only; not part of the public API

I/O Contract

Inputs

Name Type Required Description
testFile TestFile Yes Reference to the test file that contains this testing unit.
unitType UnitType Yes Enum value indicating whether this is a fixture or test.
pageUrl string Yes The initial page URL for the testing unit.
baseUrl string No An optional base URL used to resolve relative page URLs.

Outputs

Name Type Description
id string Unique identifier inherited from BaseUnit (7-character random string).
name null The name of the fixture or test, set via the chainable call.
pageUrl string The resolved page URL after validation and base-URL resolution.
authCredentials null HTTP authentication credentials if configured.
meta Metadata Dictionary of metadata key-value pairs.
only boolean Whether this unit is marked to run exclusively.
skip boolean Whether this unit is marked to be skipped.
requestHooks RequestHook[] Array of attached request hooks.
clientScripts ClientScriptInit[] Array of client scripts to inject.
apiOrigin Function The chainable API entry-point function with delegated methods.

Usage Examples

// TestingUnit is not used directly. Below shows how Fixture and Test
// inherit from it and expose the chainable API:

fixture `Authentication Tests`
    .page `https://example.com/login`
    .meta({ module: 'auth', priority: 'high' })
    .httpAuth({ username: 'admin', password: 'secret' })
    .requestHooks(myRequestHook)
    .skipJsErrors();

test
    .meta({ id: 'TC-001' })
    .page `https://example.com/dashboard`
    ('Dashboard loads correctly', async t => {
        await t.expect(true).ok();
    });

// Using .only and .skip modifiers
fixture.only `Critical Tests`
    .page `https://example.com`;

test.skip('Skipped test', async t => {
    // This test will not run
});

Related Pages

Page Connections

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