Skip to main content
Version: 7.5.5

Matchers

toBeOk

Expects the actual value to be ok.

Basic Usage

await I.expect("mySelector").toBeOk();

toExist

Expects actual element to exist.

Basic Usage

await I.expect("mySelector").toExist();

toEqual

Expects the actual value to be equal to the expected value, using deep equality comparison.

ParameterTypeDescription
expectedanyExpected value.

Basic Usage

const inputValue = `hello world`;
await I.expect(inputValue).toEqual(`hello world`);

toBeSameAs

Expects the actual value to be same as the expected.

ParameterTypeDescription
expectedanyExpected value.

Basic Usage

await I.expect("mySelector").toBeSameAs("mySelectorToCompare");

toBeSameJSONAs

Expects the actual value to have the same JSON as the expected.

ParameterTypeDescription
expectedanyExpected value.

Basic Usage

        let scrollPosition = await I.getScrollPosition();
await I.expect(scrollPosition).toBeSameJSONAs({ left: 0, top: 0 });

toBeAtLeast

Expect the actual value to be greater than or equal to the expected value. For an array, it compares if the actual array contains at least all the values of array. For an object, it compares if actual object contains at least the keys values of the expected object.

ParameterTypeDescription
expectednumber / [] / {}Expected value.

Basic Usage

await I.expect(["a","b","c"]).toBeAtLeast(["b","c"]); //array length is 3

toBeAtMost

Expect the actual value to be lower than or equal to the expected value. For an array, it asserts whether an actual array contains some or all the expected values of expected array and nothing else. For an array, it asserts whether an actual object contains some or all the expected keys values of expected object and nothing else.

ParameterTypeDescription
expectednumber / [] / {}Expected value.

Basic Usage

        await I.expect(["c"]).toBeAtMost(["b","c"]);

toBeGreaterThan

Expect the actual value to be greater than or equal to the expected value. For an array, it . For an object, it compares the value of the object keys.

ParameterTypeDescription
expectednumber / [] / {}Expected value.

Basic Usage

await I.expect(3).toBeGreaterThan(2);

toBeLessThan

Expect the actual value to be lower than or equal to the expected value. For an array, it compares the array length. For an object, it compares the value of the object keys.

ParameterTypeDescription
expectednumber / [] / {}Expected value.

Basic Usage

await I.expect(1).toBeLessThan(2);

toBeBetween

ParameterTypeDescription
expectedLowernumber / [] / {}
expectedUppernumber / [] / {}

Basic Usage

await I.expect(1).toBeBetween(0,2);

toContainAllOf

Expects the actual value to contains all of the expected values.

ParameterTypeDescription
expectedany[]Expected value.

Basic Usage

await I.expect(["a","b","c"]).toContainAllOf(["c","b","a"]);

toContainAnyOf

Expects the actual value to contains any of the expected values.

ParameterTypeDescription
expectedany[]Expected value.

Basic Usage

await I.expect(["a","b"]).toContainAnyOf(["a","b","c"]);

toContain

Expects the actual value to contains some of the expected values.

ParameterTypeDescription
expectedstring / any[]Expected value.

Basic Usage

await I.expect("text example").toContain("exam");

toStartWith

Expects the actual value to start with the expected value.

ParameterTypeDescription
expectedstringExpected value.

Basic Usage

await I.expect("mySelector").toStartWith("my");

toEndWith

Expects the actual value to end with the expected value.

ParameterTypeDescription
expectedstringExpected value.

Basic Usage

await I.expect("mySelector").toEndWith("lector");

toMatch

Expects the actual value to match a regEx.

ParameterTypeDescription
expectedRegExpExpected regEx.

Basic Usage

await I.expect("a").toMatch(/[ab]/g);

toBeInstanceOf

Expects the actual value to be of a specific instance.

ParameterTypeDescription
expectedanyExpected instance.

Basic Usage

class Foo { }
class Bar { }
let bar = new Bar();
await I.expect(bar).toBeInstanceOf(Bar).and.not.toBeInstanceOf(Foo);

toBeOfType

Expects the actual value to be of a specific type.

ParameterTypeDescription
expectedstringExpected type.

Basic Usage

 await I.expect(targetElement.innerText).toBeOfType('string');

toBeBoolean

Expects the actual value to be of boolean type.

Basic Usage

await I.expect(true).toBeBoolean();

toBeTrue

Expects the actual value to be true.

Basic Usage

await I.expect(1===1).toBeBoolean();

toBeFalse

Expects the actual value to be false.

Basic Usage

await I.expect(1===2).toBeFalse();

toBeFalsy

Expects the actual value to be falsy.

Basic Usage

await I.expect(1==2).toBeFalsy();

toBeUndefined

Expects the actual value to be undefined.

Basic Usage

let a;
await I.expect(a).toBeUndefined();

toBeNull

Expects the actual value to be null.

Basic Usage

await I.expect(null).toBeNull();

toBeNan

Expects the actual value not to be a number.

Basic Usage

await I.expect("mySelector").toBeNan();

toThrow

Expect expression to throw something.

ParameterTypeDescription
expectedstring / RegExp / ((ex: Error) => boolean)

Basic Usage

await I.expect(Error).toThrow("Expected error message");

not

Keyword to negate an assertion.Invert the matcher following this expect.

Basic Usage

await I.expect(12).not.toBeUndefined();

or

Keyword to have an or condition between several assertions.

Basic Usage

await I.expect(Selector("#idElement")).toExist().or.toBeUndefined();

and

Keyword to chain assertions.

Basic Usage

await I.expect(Selector("#idElement")).toExist().and.toBeVisible();