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