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
npm install jest-expect-message
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
362 Stars
45 Commits
42 Forks
8 Watching
3 Branches
7 Contributors
Updated on 07 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-20.8%
57,205
Compared to previous day
Last week
-1.3%
350,597
Compared to previous week
Last month
10.8%
1,428,951
Compared to previous month
Last year
38.8%
12,318,756
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
6 existing vulnerabilities detected
Details
Reason
Found 6/29 approved changesets -- score normalized to 2
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
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
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 2024-11-18
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