t.expect.notEql Method
Assertion method. Succeeds if x
does not equal y
.
t.expect(x).notEql(y, message, options) → this | Promise<unknown>
Parameter | Type | Description |
---|---|---|
x |
Any type | The first operand of the assertion (see the x parameter). |
y |
Any type | The second operand of the assertion. |
message (optional) |
String | Custom assertion error message. |
options (optional) |
Object | See Options. |
Examples:
try {
await t.expect({ a: 'bar' }).notEql({ a: 'bar' }, 'this assertion will fail');
}
catch (e) {
await t.expect(e.errMsg).eql('AssertionError: this assertion will fail: expected { a: \'bar\' } to not deeply equal { a: \'bar\' }');
}
await t.expect({ a: 'bar' }).notEql({ a: 'foo' }, 'this assertion will pass');
import { Selector } from 'testcafe';
fixture`TestController.expect.notEql`
.page`https://devexpress.github.io/testcafe/example/`;
test('Check count of columns', async t => {
await t.expect(Selector('.column').count).notEql(3);
});
the x
parameter
x
is the first operand of the assertion.
If the first operand contains a selector property, a client function, or any other compatible function, the assertion becomes subject to the Smart Assertion Query Mechanism.
Different assertion methods accept different arguments. Make sure that your operands belong to compatible data types.
Options
options.timeout
Type: Number
If an assertion’s first operand contains a compatible function, the assertion is subject to the Smart Assertion Query Mechanism.
If such an assertion fails, TestCafe executes it again until it meets either of the following criteria:
- The assertion succeeds.
- The assertion timeout elapses.
await t.expect(Selector('h1').innerText).eql('text', 'check element text', { timeout: 20000 });
To set the timeout for the entire test run, define the assertion timeout in one of the following ways:
- Set the assertionTimeout configuration file option.
- Set the assertion-timeout CLI option.
- Set the assertionTimeout Runner API option.
Note
The timeout
option applies to built-in TestCafe assertion methods. Use the t.wait() method to specify timeouts for third-party assertion methods (assert or chai).
options.allowUnawaitedPromise
TestCafe awaits Promises from compatible asynchronous functions. If your assertion includes a custom function that returns a Promise, the assertion fails.
When you create assertions, avoid the use of custom functions that return a Promise. If you can’t work around this limitation, use the allowUnawaitedPromise
option:
await t
.expect(new Promise(resolve => setTimeout(resolve, 100)))
.ok('received a promise', { allowUnawaitedPromise: true });