Gathering detailed insights and metrics for jest-expect-message
Gathering detailed insights and metrics for jest-expect-message
Gathering detailed insights and metrics for jest-expect-message
Gathering detailed insights and metrics for jest-expect-message
@types/jest-expect-message
Stub TypeScript definitions entry for jest-expect-message, which provides its own types definitions
@alex_neo/jest-expect-message
Add custom message to Jest expects
jest-27-expect-message
Add custom message to Jest expects
@jason0x43/jest-expect-message
Add custom message to Jest expects
npm install jest-expect-message
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
368 Stars
45 Commits
41 Forks
7 Watchers
3 Branches
7 Contributors
Updated on Jun 25, 2025
Latest Version
1.1.3
Package Id
jest-expect-message@1.1.3
Unpacked Size
12.41 kB
Size
4.23 kB
File Count
6
NPM Version
8.15.0
Node Version
16.17.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
🃏🗯
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.
For example:
1test('returns 2 when adding 1 and 1', () => { 2 expect(1 + 1, 'Woah this should be 2!').toBe(3); 3});
This will throw the following error in Jest:
1Expect takes at most one argument.
jest-expect-message
allows you to call expect
with a second argument of a String
message.
For example the same test as above:
1test('returns 2 when adding 1 and 1', () => { 2 expect(1 + 1, 'Woah this should be 2!').toBe(3); 3});
With jest-expect-message
this will fail with your custom error message:
1 ● returns 2 when adding 1 and 1 2 3 Custom message: 4 Woah this should be 2! 5 6 expect(received).toBe(expected) // Object.is equality 7 8 Expected: 3 9 Received: 2
With npm:
1npm install --save-dev jest-expect-message
With yarn:
1yarn add -D jest-expect-message
Add jest-expect-message
to your Jest setupFilesAfterEnv
configuration.
See for help
1"jest": { 2 "setupFilesAfterEnv": ["jest-expect-message"] 3}
1"jest": { 2 "setupTestFrameworkScriptFile": "jest-expect-message" 3}
If you have a custom setup file and want to use this library then add the following to your setup file.
1import 'jest-expect-message';
Add the following entry to your tsconfig to enable Typescript support.
1 "files": ["node_modules/jest-expect-message/types/index.d.ts"],
Custom message example with typescript
1"rules": { 2 "jest/valid-expect": [ 3 "error", 4 { 5 "maxArgs": 2 6 } 7 ] 8}
expect(actual, message, options?)
actual
: The value you would normally pass into an expect
to assert against with a given matcher.message
: String, the custom message you want to be printed should the expect
fail.options
: An optional object that controls what is shown as part of the custom message.
showPrefix: boolean
: If false
will not show the Custom message:
prefix. Default: true
showMatcherMessage: boolean
: If false
will not show the matchers original error message. Default: true
showStack: boolean
: If false
will not show the matchers stack trace. Default: true
1test('returns 2 when adding 1 and 1', () => { 2 expect(1 + 1, 'Woah this should be 2!').toBe(3); 3}); 4// ↓ ↓ ↓ ↓ ↓ ↓ 5/* 6 ● returns 2 when adding 1 and 1 7 8 Custom message: 9 Woah this should be 2! 10 11 expect(received).toBe(expected) // Object.is equality 12 13 Expected: 3 14 Received: 2 15 16 1 | test('returns 2 when adding 1 and 1', () => { 17> 2 | expect(1 + 1, 'Woah this should be 2!').toBe(3); 18 | ^ 19 3 | }); 20*/
false
1test('returns 2 when adding 1 and 1', () => { 2 expect(1 + 1, 'Woah this should be 2!', { showPrefix: false }).toBe(3); 3}); 4// ↓ ↓ ↓ ↓ ↓ ↓ 5/* 6 ● returns 2 when adding 1 and 1 7 8 Woah this should be 2! 9 10 expect(received).toBe(expected) // Object.is equality 11 12 Expected: 3 13 Received: 2 14 15 1 | test('returns 2 when adding 1 and 1', () => { 16> 2 | expect(1 + 1, 'Woah this should be 2!', { showPrefix: false }).toBe(3); 17 | ^ 18 3 | }); 19*/
false
1test('returns 2 when adding 1 and 1', () => { 2 expect(1 + 1, 'Woah this should be 2!', { showMatcherMessage: false }).toBe(3); 3}); 4// ↓ ↓ ↓ ↓ ↓ ↓ 5/* 6 ● returns 2 when adding 1 and 1 7 8 Custom message: 9 Woah this should be 2! 10 11 1 | test('returns 2 when adding 1 and 1', () => { 12> 2 | expect(1 + 1, 'Woah this should be 2!', { showMatcherMessage: false }).toBe(3); 13 | ^ 14 3 | }); 15*/
false
1test('returns 2 when adding 1 and 1', () => { 2 expect(1 + 1, 'Woah this should be 2!', { showStack: false }).toBe(3); 3}); 4// ↓ ↓ ↓ ↓ ↓ ↓ 5/* 6 ● returns 2 when adding 1 and 1 7 8 Custom message: 9 Woah this should be 2! 10 11 expect(received).toBe(expected) // Object.is equality 12 13 Expected: 3 14 Received: 2 15*/
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
Found 6/29 approved changesets -- score normalized to 2
Reason
8 existing vulnerabilities detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More