t.expect Method

This method accepts the actual value.

You can pass a value, a Selector’s DOM node state property or a client function promise. TestCafe automatically waits for node state properties to obtain a value and for client functions to execute. See Smart Assertion Query Mechanism for details.

The value passed as the actual parameter should be a data type the assertion method accepts.

note

You cannot pass a regular promise to the expect method unless the options.allowUnawaitedPromise option is enabled.

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 });

The expect method is followed by an assertion method that accepts an expected value and optional arguments. The following assertion methods are available:

The code snippet below demonstrates how to use expect method in a test:

import { Selector } from 'testcafe';


fixture `Example page`
   .page `http://devexpress.github.io/testcafe/example/`;


test('Check property of element', async t => {
   const developerNameInput = Selector('#developer-name');

   await t
       .expect(developerNameInput.value).eql('', 'input is empty')
       .typeText(developerNameInput, 'Peter Parker')
       .expect(developerNameInput.value).contains('Peter', 'input contains text "Peter"');
});