Add custom message to Jest expects
In many testing libraries it is possible to supply a custom message for a given expectation, this is currently not possible in Jest.
This will throw the following error in Jest:
Expect takes at most one argument.
jest-expect-message allows you to call
expect with a second argument of a
For example the same test as above:
jest-expect-message this will fail with your custom error message:
● returns 2 when adding 1 and 1Custom message:Woah this should be 2!expect.toBe // Object.is equalityExpected: 3Received: 2
npm install --save-dev jest-expect-message
yarn add -D jest-expect-message
jest-expect-message to your Jest
See for help
actual: The value you would normally pass into an
expectto assert against with a given matcher.
message: String, the custom message you want to be printed should the
💻 📖 💡 🤔 🚇 ⚠️ 🔧