What is @jest/expect-utils?
@jest/expect-utils is a utility package for Jest that provides additional matchers and utilities to enhance the testing experience. It is designed to work seamlessly with Jest's built-in expect function, allowing for more expressive and readable test assertions.
What are @jest/expect-utils's main functionalities?
toBeArray
Checks if the value is an array.
expect([1, 2, 3]).toBeArray();
toBeObject
Checks if the value is an object.
expect({ key: 'value' }).toBeObject();
toBeEmpty
Checks if the value is empty. This can be used for arrays, objects, or strings.
expect([]).toBeEmpty();
toContainKey
Checks if the object contains the specified key.
expect({ key: 'value' }).toContainKey('key');
toContainValue
Checks if the object contains the specified value.
expect({ key: 'value' }).toContainValue('value');
Other packages similar to @jest/expect-utils
jest-extended
jest-extended provides a large number of additional matchers for Jest. It offers a wide range of matchers similar to @jest/expect-utils, such as toBeArray, toBeObject, and toBeEmpty, but also includes many more specialized matchers.
chai
Chai is an assertion library for Node.js and the browser that can be paired with any testing framework. It provides a rich set of matchers and is highly extensible. While it is not specifically designed for Jest, it offers similar functionalities through its expect/should interfaces.
expect-more
expect-more is a set of additional matchers for Jest and Jasmine. It provides a variety of matchers for different data types and use cases, similar to @jest/expect-utils, and aims to make tests more expressive and readable.
@jest/expect-utils
This module exports some utils for the expect
function used in Jest.
You probably don't want to use this package directly. E.g. if you're writing custom matcher, you should use the injected this.equals
.