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 ClientFunction TypeDefs

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

Overview

Concrete TypeScript type declarations for TestCafe's ClientFunction API, enabling test authors to execute arbitrary JavaScript in the browser context.

Description

This file declares ClientFunctionOptions (with dependencies and boundTestRun) and the ClientFunction interface. ClientFunction wraps a JavaScript function that runs in the browser, with typed return values and argument lists. The with method allows overriding options on an existing client function instance.

Usage

Use these types for TypeScript IntelliSense when creating client functions that execute browser-side JavaScript from test code.

Code Reference

Source Location

Signature

interface ClientFunctionOptions {
    dependencies?: { [key: string]: any };
    boundTestRun?: TestController;
}

interface ClientFunction<R = any, A extends any[] = any[]> {
    (...args: A): Promise<R>;
    with(options?: ClientFunctionOptions): ClientFunction<R, A>;
}

interface ClientFunctionFactory {
    <R = any, A extends any[] = any[]>(
        fn: (...args: A) => R,
        options?: ClientFunctionOptions
    ): ClientFunction<R, A>;
}

Import

import { ClientFunction } from 'testcafe';

I/O Contract

Inputs

Name Type Required Description
fn Function Yes JavaScript function to execute in the browser
options ClientFunctionOptions No Dependencies and test run binding

Outputs

Name Type Description
ClientFunction (...args) => Promise<R> Callable that returns a promise resolving to browser-side result

Usage Examples

import { ClientFunction } from 'testcafe';

const getPageTitle = ClientFunction(() => document.title);
const getWindowLocation = ClientFunction(() => window.location.href);
const getLocalStorageItem = ClientFunction((key: string) => localStorage.getItem(key));

fixture('ClientFunction').page('https://example.com');

test('Get browser-side data', async (t: TestController) => {
    const title = await getPageTitle();
    await t.expect(title).eql('Example Domain');

    const url = await getWindowLocation();
    await t.expect(url).contains('example.com');

    // With dependencies
    const customFn = ClientFunction((selector: string) => {
        return document.querySelector(selector)?.textContent;
    });

    const text = await customFn('h1');
    await t.expect(text).eql('Example Domain');
});

Related Pages

Page Connections

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