t.expect.notWithin Method

Asserts that actual is not within a range from start to finish. Bounds are inclusive.

t.expect(actual).notWithin(start, finish, message, options) → this | Promise<unknown>
Parameter Type Description
actual Number A comparison value. See actual parameter value.
start Number The lower range (included).
finish Number The upper range (included).
message (optional) String An assertion message displayed in the report if the test fails.
options (optional) Object See Options.


await t.expect(1).notWithin(3, 10, 'this assertion will pass');
import { Selector } from 'testcafe';


test('ScrollTop of the \'html\' element shouldn\'t be within 100 and 200', async t => {
    await t.scroll('html', 'bottom');
    await t.expect(Selector('html').scrollTop).notWithin(100, 200);

actual Parameter Value

actual is a parameter that defines the value that TestCafe checks with assertion methods.

You can pass a selector’s property or a client function promise as the value of this parameter. This activates the Smart Assertion Query Mechanism and the assertion automatically waits until it can obtain the actual value.

The value passed as the actual parameter needs to be of the data type supported by the assertion method.



Type: Number

The time (in milliseconds) an assertion can take to pass before the test fails if a selector property or client function promise is used.

Default value: The timeout is specified with the runner.run API method or the assertion-timeout command line option.

await t.expect(Selector('h1').innerText).eql('text', 'check element text', { timeout: timeoutValue });


In addition to built-in assertions, you also can use assertions from Node.js’s assert module or 3rd-party library (for example chai). In this case, specify the time required to complete asynchronous actions with the t.wait(timeout) method.


Only promises the selectors and client functions return can be passed as the assertion’s actual value. If you pass a regular unawaited promise, TestCafe throws an error.

If you need to assert a regular promise, set the allowUnawaitedPromise option to true.

await t.expect(new Promise(resolve => setTimeout(resolve, 100))).ok('check that a promise is returned', { allowUnawaitedPromise: true });