Implementation:DevExpress Testcafe ClientFunction TypeDefs
| 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
- Repository: DevExpress_Testcafe
- File: ts-defs-src/test-api/client-function.d.ts
- Lines: 1-36
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');
});