t.expect.notContains Method

Asserts that actual does not contain expected.

await t.expect( actual ).notContains( expected, message, options );
Parameter Type Description
actual String | Array | Object A value tested in assertion. The assertion passes if the actual value does not contain the expected. See actual parameter value.
expected Any type The value expected not to contain the actual.
message (optional) String An assertion message displayed in the report if the test fails.
options (optional) Object See Options.

Examples:

await t
    .expect('foo bar').notContains('baz', 'string does not contain a substring')
    .expect([1, 2, 3]).notContains(4, 'array does not contain a value')
    .expect({ foo: 'bar', hello: 'universe' }).notContains({ buzz: 'abc' }, 'object does not contain a property');
import { ClientFunction } from 'testcafe';

fixture `My fixture`;

test('My test', async t => {
    const getLocation = ClientFunction(() => document.location.href.toString());

    await t.expect(getLocation()).notContains('devexpress.com');
});

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.

Options

options.timeout

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('#elementId').innerText).eql('text', 'check element text', { timeout: 500 });

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.

options.allowUnawaitedPromise

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(doSomethingAsync()).ok('check that a promise is returned', { allowUnawaitedPromise: true });