Implementation:DevExpress Testcafe Assertions TypeDefs
| Knowledge Sources | |
|---|---|
| Domains | Type_Definitions, Testing, Assertions |
| Last Updated | 2026-02-12 12:00 GMT |
Overview
Concrete TypeScript type declarations for TestCafe's Assertion interface providing all assertion methods available on the t.expect() chain.
Description
This file defines the AssertionOptions interface (with timeout and allowUnawaitedPromise) and the generic Assertion<E> interface that provides methods: eql, notEql, ok, notOk, contains, notContains, typeOf, notTypeOf, gt, gte, lt, lte, within, notWithin, and match/notMatch. Each method returns TestControllerPromise for chaining and accepts optional AssertionOptions.
Usage
These types power TypeScript IntelliSense for t.expect(value).eql(expected) assertion chains in test files.
Code Reference
Source Location
- Repository: DevExpress_Testcafe
- File: ts-defs-src/test-api/assertions.d.ts
- Lines: 1-261
Signature
interface AssertionOptions {
timeout?: number;
allowUnawaitedPromise?: boolean;
}
interface Assertion<E> {
eql(expected: E, message?: string, opts?: AssertionOptions): TestControllerPromise;
notEql(unexpected: E, message?: string, opts?: AssertionOptions): TestControllerPromise;
ok(message?: string, opts?: AssertionOptions): TestControllerPromise;
notOk(message?: string, opts?: AssertionOptions): TestControllerPromise;
contains(expected: any, message?: string, opts?: AssertionOptions): TestControllerPromise;
notContains(unexpected: any, message?: string, opts?: AssertionOptions): TestControllerPromise;
typeOf(typeName: string, message?: string, opts?: AssertionOptions): TestControllerPromise;
notTypeOf(typeName: string, message?: string, opts?: AssertionOptions): TestControllerPromise;
gt(expected: number, message?: string, opts?: AssertionOptions): TestControllerPromise;
gte(expected: number, message?: string, opts?: AssertionOptions): TestControllerPromise;
lt(expected: number, message?: string, opts?: AssertionOptions): TestControllerPromise;
lte(expected: number, message?: string, opts?: AssertionOptions): TestControllerPromise;
within(start: number, finish: number, message?: string, opts?: AssertionOptions): TestControllerPromise;
notWithin(start: number, finish: number, message?: string, opts?: AssertionOptions): TestControllerPromise;
match(re: RegExp, message?: string, opts?: AssertionOptions): TestControllerPromise;
notMatch(re: RegExp, message?: string, opts?: AssertionOptions): TestControllerPromise;
}
Import
// Automatically available in TestCafe TypeScript test files
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| actual | E (generic) | Yes | Value to assert (from t.expect(actual)) |
| expected | E | Yes | Expected value for comparison assertions |
| message | string | No | Custom error message on failure |
| opts | AssertionOptions | No | Timeout and allowUnawaitedPromise options |
Outputs
| Name | Type | Description |
|---|---|---|
| TestControllerPromise | TestController & Promise | Enables chaining after assertions |
Usage Examples
import { Selector } from 'testcafe';
fixture('Assertions').page('https://example.com');
test('Assertion methods', async (t: TestController) => {
// Equality
await t.expect(Selector('h1').textContent).eql('Welcome');
await t.expect(Selector('.count').textContent).notEql('0');
// Truthiness
await t.expect(Selector('#element').exists).ok();
await t.expect(Selector('.error').exists).notOk();
// Contains
await t.expect(Selector('p').textContent).contains('important');
// Numeric comparisons
await t.expect(Selector('.items').count).gt(0);
await t.expect(Selector('.items').count).lte(100);
await t.expect(Selector('.progress').textContent).within(0, 100);
// Regex matching
await t.expect(Selector('.email').textContent).match(/\w+@\w+\.\w+/);
// With timeout option
await t.expect(Selector('.loading').exists).notOk('Still loading', { timeout: 10000 });
});