GenericAssertions.toBe method
The toBe method compares value with expected by calling Object.is. This method compares objects by reference instead of their contents, similarly to the strict equality operator ===. It takes one parameter: expected (any type).
GenericAssertions.toBeCloseTo method
The toBeCloseTo method compares floating point numbers for approximate equality. Use this instead of toBe when comparing floating point numbers. Parameters: expected (float, required), numDigits (int, optional) - the number of decimal digits after the decimal point that must be equal.
GenericAssertions.toBeFalsy method
The toBeFalsy method ensures that value is false in a boolean context, one of false, 0, '', null, undefined or NaN. Use this method when you don't care about the specific value.
GenericAssertions.toBeGreaterThanOrEqual method
The toBeGreaterThanOrEqual method ensures that value >= expected for number or big integer values. Parameters: expected (float|bigint, required) - the value to compare to.
GenericAssertions.toBeInstanceOf method
The toBeInstanceOf method ensures that value is an instance of a class. Uses instanceof operator. Parameters: expected (Function, required) - the class or constructor function.
GenericAssertions.toBeLessThanOrEqual method
The toBeLessThanOrEqual method ensures that value <= expected for number or big integer values. Parameters: expected (float|bigint, required) - the value to compare to.
GenericAssertions.toBeNaN method
The toBeNaN method ensures that value is NaN.
GenericAssertions.toBeNull method
The toBeNull method ensures that value is null.
GenericAssertions.toBeTruthy method
The toBeTruthy method ensures that value is true in a boolean context, anything but false, 0, '', null, undefined or NaN. Use this method when you don't care about the specific value.
GenericAssertions.toBeUndefined method
The toBeUndefined method ensures that value is undefined.
GenericAssertions.toContain string method
The toContain method (string variant) ensures that string value contains an expected substring. Comparison is case-sensitive. Parameters: expected (string, required) - expected substring.
GenericAssertions.toContain array/set method
The toContain method (array/set variant) ensures that value is an Array or Set and contains an expected item. Parameters: expected (any, required) - expected value in the collection.
GenericAssertions.toContainEqual method
The toContainEqual method ensures that value is an Array or Set and contains an item equal to the expected. For objects, this method recursively checks equality of all fields, rather than comparing objects by reference. For primitive values, it is equivalent to toContain. Parameters: expected (any, required) - expected value in the collection.
GenericAssertions.toEqual method
The toEqual method compares contents of the value with contents of expected, performing deep equality check. For objects, recursively checks equality of all fields. For primitive values, equivalent to toBe. It ignores undefined properties and array items, and does not insist on object types being equal. For stricter matching, use toStrictEqual. Parameters: expected (any, required) - expected value.
GenericAssertions.toEqual pattern matching
The toEqual method supports pattern matching on objects, arrays and primitive types using matchers: any(), anything(), arrayContaining(), arrayOf(), closeTo(), objectContaining(), stringContaining(), and stringMatching().
GenericAssertions.toHaveLength method
The toHaveLength method ensures that value has a .length property equal to expected. Useful for arrays and strings. Parameters: expected (int, required) - expected length.
GenericAssertions.toHaveProperty method
The toHaveProperty method ensures that property at provided keyPath exists on the object and optionally checks that property is equal to the expected. Equality is checked recursively, similarly to toEqual. Parameters: keyPath (string, required) - path to the property using dot notation a.b for nested properties and indexed a[2] notation for array items; expected (any, optional) - optional expected value to compare the property to.
GenericAssertions.toMatch method
The toMatch method ensures that string value matches a regular expression. Parameters: expected (RegExp|string, required) - regular expression to match against.
GenericAssertions.toMatchObject method
The toMatchObject method compares contents of the value with contents of expected, performing deep equality check. Allows extra properties to be present in the value, unlike toEqual. When comparing arrays, the number of items must match, and each item is checked recursively. Parameters: expected (Object|Array, required) - the expected object value to match against.
GenericAssertions.toStrictEqual method
The toStrictEqual method compares contents of the value with contents of expected and their types. Differences from toEqual: keys with undefined properties are checked (e.g., {a: undefined, b: 2} does not match {b: 2}), array sparseness is checked (e.g., [, 1] does not match [undefined, 1]), and object types are checked to be equal. Parameters: expected (any, required) - expected value.
GenericAssertions.toThrow method
The toThrow method calls the function and ensures it throws an error. Optionally compares the error with expected. Allowed expected values: regular expression (error message should match the pattern), string (error message should include the substring), error object (error message should be equal to the message property), error class (error object should be an instance of the class). Parameters: expected (any, optional) - expected error message or error object.
GenericAssertions.toThrowError method
The toThrowError method is an alias for toThrow. Parameters: expected (any, optional) - expected error message or error object.
GenericAssertions.any matcher
The any() matcher matches any object instance created from the constructor or a corresponding primitive type. Use it inside toEqual to perform pattern matching. Parameters: constructor (Function, required) - constructor of the expected object like ExampleClass, or a primitive boxed type like Number.
GenericAssertions.anything matcher
The anything() matcher matches everything except null and undefined. Use it inside toEqual to perform pattern matching.
GenericAssertions.arrayContaining matcher
The arrayContaining() matcher matches an array that contains all of the elements in the expected array, in any order. Note that received array may be a superset of the expected array and contain extra elements. Use it inside toEqual to perform pattern matching. Parameters: expected (Array<any>, required) - expected array that is a subset of the received value.
GenericAssertions.arrayOf matcher
The arrayOf() matcher (available since v1.57) matches array of objects created from the constructor or a corresponding primitive type. Use it inside toEqual to perform pattern matching. Parameters: constructor (Function, required) - constructor of the expected object like ExampleClass, or a primitive boxed type like Number.
GenericAssertions.closeTo matcher
The closeTo() matcher compares floating point numbers for approximate equality. Use it inside toEqual to perform pattern matching. When just comparing two numbers, prefer toBeCloseTo. Parameters: expected (float, required) - expected value; numDigits (int, optional) - the number of decimal digits after the decimal point that must be equal.
GenericAssertions.objectContaining matcher
The objectContaining() matcher matches an object that contains and matches all of the properties in the expected object. Note that received object may be a superset of the expected object and contain extra properties. Use it inside toEqual to perform pattern matching. Object properties can be matchers to further relax the expectation. Parameters: expected (Object, required) - expected object pattern that contains a subset of the properties.
GenericAssertions.stringContaining matcher
The stringContaining() matcher matches a string that contains the expected substring. Use it inside toEqual to perform pattern matching. Parameters: expected (string, required) - expected substring.
GenericAssertions.stringMatching matcher
The stringMatching() matcher matches a received string that in turn matches the expected pattern. Use it inside toEqual to perform pattern matching. Parameters: expected (string|RegExp, required) - pattern that expected string should match.