Setup
caution
jest-extended
only supports Jest version 27.2.5
and newer. If you're using an older version of Jest, use 1.2.1
.
Create a setup script with the following:
// ./testSetup.js
// add all jest-extended matchers
import * as matchers from 'jest-extended';
expect.extend(matchers);
// or just add specific matchers
import { toBeArray, toBeSealed } from 'jest-extended';
expect.extend({ toBeArray, toBeSealed });
Add your setup script to your Jest setupFilesAfterEnv
configuration. See for help
"jest": {
"setupFilesAfterEnv": ["./testSetup.js"]
}
To automatically extend expect
with all matchers, you can use
"jest": {
"setupFilesAfterEnv": ["jest-extended/all"]
}