Implementation:DevExpress Testcafe Request TypeDefs
| Knowledge Sources | |
|---|---|
| Domains | Type_Definitions, Testing, HTTP_Requests |
| Last Updated | 2026-02-12 12:00 GMT |
Overview
Concrete TypeScript type declarations for TestCafe's HTTP Request API (t.request), allowing server-side HTTP requests directly from test code.
Description
This file defines the RequestOptions interface (with URL, method, headers, body, auth, proxy, rawResponse, timeout), the ResponseBody interface, and the RequestAPI interface providing HTTP methods: request() (general), request.get(), request.post(), request.put(), request.delete(), request.patch(), request.head(). Each method returns a Promise resolving to a typed response object.
Usage
Use t.request when tests need to directly call server APIs (for setup, verification, or data preparation) without going through the browser.
Code Reference
Source Location
- Repository: DevExpress_Testcafe
- File: ts-defs-src/test-api/request.d.ts
- Lines: 1-158
Signature
interface RequestOptions {
url?: string | URL;
method?: string;
headers?: Record<string, string>;
body?: any;
timeout?: number;
auth?: { username: string; password: string; };
proxy?: { protocol?: string; host: string; port: number | string; auth?: { username: string; password: string; }; };
rawResponse?: boolean;
withCredentials?: boolean;
}
interface ResponseBody {
status: number;
statusText: string;
headers: Record<string, string>;
body: any;
}
interface RequestAPI {
(urlOrOptions: string | RequestOptions, options?: RequestOptions): Promise<ResponseBody>;
get(urlOrOptions: string | RequestOptions, options?: RequestOptions): Promise<ResponseBody>;
post(urlOrOptions: string | RequestOptions, options?: RequestOptions): Promise<ResponseBody>;
delete(urlOrOptions: string | RequestOptions, options?: RequestOptions): Promise<ResponseBody>;
put(urlOrOptions: string | RequestOptions, options?: RequestOptions): Promise<ResponseBody>;
patch(urlOrOptions: string | RequestOptions, options?: RequestOptions): Promise<ResponseBody>;
head(urlOrOptions: string | RequestOptions, options?: RequestOptions): Promise<ResponseBody>;
}
Import
// Available as t.request in test functions
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| url | string or URL | Yes | Target URL |
| method | string | No | HTTP method (defaults based on helper used) |
| headers | Record<string, string> | No | Request headers |
| body | any | No | Request body (auto-serialized) |
Outputs
| Name | Type | Description |
|---|---|---|
| ResponseBody | object | Status, headers, and parsed body |
Usage Examples
fixture('HTTP Request API').page('https://example.com');
test('Make API calls from tests', async (t: TestController) => {
// GET request
const users = await t.request.get('https://api.example.com/users');
await t.expect(users.status).eql(200);
await t.expect(users.body.length).gt(0);
// POST request with body
const created = await t.request.post('https://api.example.com/users', {
body: { name: 'Test User', email: 'test@example.com' },
headers: { 'Content-Type': 'application/json' },
});
await t.expect(created.status).eql(201);
// DELETE with auth
await t.request.delete('https://api.example.com/users/1', {
auth: { username: 'admin', password: 'secret' },
});
});