expect-helper
Expect helper for I.expect calls
Installation:
npm i @codeceptjs/expect-helper --save
Enable it inside codecept conf file:
// inside codecept.conf.js/ts
{
helpers: {
Playwright: {...},
ExpectHelper: {
require: '@codeceptjs/expect-helper'
},
}
}
Usage
I.expectEqual
Asserts that the actual value is equal to the expected value.
I.expectEqual(actualValue, expectedValue, customErrorMsg = '')
actualValue: The actual value to be compared.
expectedValue: The expected value to compare against.
customErrorMsg: (Optional) Custom error message to display if the assertion fails.
Example:
I.expectEqual(5, 5); // Passes
I.expectEqual('hello', 'hello'); // Passes
I.expectEqual(5, 10, 'Values are not equal'); // Fails with custom error message
I.expectNotEqual
Asserts that the actual value is not equal to the expected value.
I.expectNotEqual(actualValue, expectedValue, customErrorMsg = '')
actualValue: The actual value to be compared.
expectedValue: The expected value to compare against.
customErrorMsg: (Optional) Custom error message to display if the assertion fails.
Example:
I.expectNotEqual(5, 10); // Passes
I.expectNotEqual('hello', 'world'); // Passes
I.expectNotEqual(5, 5, 'Values should not be equal'); // Fails with custom error message
I.expectDeepEqual
Asserts that the actual value is deeply equal to the expected value.
I.expectDeepEqual(actualValue, expectedValue, customErrorMsg = '')
actualValue: The actual value to be compared.
expectedValue: The expected value to compare against.
customErrorMsg: (Optional) Custom error message to display if the assertion fails.
Example:
I.expectDeepEqual({ a: 1 }, { a: 1 }); // Passes
I.expectDeepEqual([1, 2, 3], [1, 2, 3]); // Passes
I.expectDeepEqual({ a: 1 }, { a: 2 }, 'Objects are not deeply equal'); // Fails with custom error message
I.expectNotDeepEqual
Asserts that the actual value is not deeply equal to the expected value.
I.expectNotDeepEqual(actualValue, expectedValue, customErrorMsg = '')
actualValue: The actual value to be compared.
expectedValue: The expected value to compare against.
customErrorMsg: (Optional) Custom error message to display if the assertion fails.
Example:
I.expectNotDeepEqual({ a: 1 }, { a: 2 }); // Passes
I.expectNotDeepEqual([1, 2, 3], [4, 5, 6]); // Passes
I.expectNotDeepEqual({ a: 1 }, { a: 1 }, 'Objects should not be deeply equal'); // Fails with custom error message
I.expectContain
Asserts that the actual value contains the expected value.
I.expectContain(actualValue, expectedValueToContain, customErrorMsg = '')
actualValue: The actual value to be checked.
expectedValueToContain: The value expected to be contained within the actual value.
customErrorMsg: (Optional) Custom error message to display if the assertion fails.
Example:
I.expectContain([1, 2, 3], 2); // Passes
I.expectContain('hello world', 'world'); // Passes
I.expectContain([1, 2, 3], 4, 'Array does not contain the value'); // Fails with custom error message
I.expectNotContain
Asserts that the actual value does not contain the expected value.
I.expectNotContain(actualValue, expectedValueToNotContain, customErrorMsg = '')
actualValue: The actual value to be checked.
expectedValueToNotContain: The value expected not to be contained within the actual value.
customErrorMsg: (Optional) Custom error message to display if the assertion fails.
Example:
I.expectNotContain([1, 2, 3], 4); // Passes
I.expectNotContain('hello world', 'universe'); // Passes
I.expectNotContain([1, 2, 3], 2, 'Array should not contain the value'); // Fails with custom error message
I.expectStartsWith
Asserts that the actual value starts with the expected value.
I.expectStartsWith(actualValue, expectedValueToStartWith, customErrorMsg = '')
actualValue: The actual value to be checked.
expectedValueToStartWith: The value expected to be at the start of the actual value.
customErrorMsg: (Optional) Custom error message to display if the assertion fails.
Example:
I.expectStartsWith('hello world', 'hello'); // Passes
I.expectStartsWith([1, 2, 3], 1); // Passes
I.expectStartsWith('hello world', 'world', 'String does not start with the value'); // Fails with custom error message
I.expectNotStartsWith
Asserts that the actual value does not start with the expected value.
I.expectNotStartsWith(actualValue, expectedValueToNotStartWith, customErrorMsg = '')
actualValue: The actual value to be checked.
expectedValueToNotStartWith: The value expected not to be at the start of the actual value.
customErrorMsg: (Optional) Custom error message to display if the assertion fails.
Example:
I.expectNotStartsWith('hello world', 'world'); // Passes
I.expectNotStartsWith([1, 2, 3], 2); // Passes
I.expectNotStartsWith('hello world', 'hello', 'String should not start with the value'); // Fails with custom error message
I.expectEndsWith
Asserts that the actual value ends with the expected value.
I.expectEndsWith(actualValue, expectedValueToEndWith, customErrorMsg = '')
actualValue: The actual value to be checked.
expectedValueToEndWith: The value expected to be at the end of the actual value.
customErrorMsg: (Optional) Custom error message to display if the assertion fails.
Example:
I.expectEndsWith('hello world', 'world'); // Passes
I.expectEndsWith([1, 2, 3], 3); // Passes
I.expectEndsWith('hello world', 'hello', 'String does not end with the value'); // Fails with custom error message
I.expectNotEndsWith
Asserts that the actual value does not end with the expected value.
I.expectNotEndsWith(actualValue, expectedValueToNotEndWith, customErrorMsg = '')
actualValue: The actual value to be checked.
expectedValueToNotEndWith: The value expected not to be at the end of the actual value.
customErrorMsg: (Optional) Custom error message to display if the assertion fails.
Example:
I.expectNotEndsWith('hello world', 'hello'); // Passes
I.expectNotEndsWith([1, 2, 3], 2); // Passes
I.expectNotEndsWith('hello world', 'world', 'String should not end with the value'); // Fails with custom error message
I.expectJsonSchema
Asserts that the target data matches the provided JSON schema using AJV.
I.expectJsonSchema(targetData, jsonSchema, customErrorMsg = '')
targetData: The data to be validated against the schema.
jsonSchema: The JSON schema to validate against.
customErrorMsg: (Optional) Custom error message to display if the assertion fails.
Example: