{"id":13484126,"url":"https://github.com/mattphillips/jest-expect-message","last_synced_at":"2025-05-15T17:06:03.849Z","repository":{"id":32831554,"uuid":"143859459","full_name":"mattphillips/jest-expect-message","owner":"mattphillips","description":"Add custom message to Jest expects 🃏🗯","archived":false,"fork":false,"pushed_at":"2024-07-17T07:01:04.000Z","size":325,"stargazers_count":369,"open_issues_count":13,"forks_count":41,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-12T12:05:41.459Z","etag":null,"topics":["custom","expect","jest","message","test"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/jest-expect-message","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mattphillips.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"docs/ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["mattphillips"]}},"created_at":"2018-08-07T10:45:19.000Z","updated_at":"2025-04-14T11:29:45.000Z","dependencies_parsed_at":"2024-02-04T16:20:17.042Z","dependency_job_id":"cff17d63-3477-4d45-90d3-3ef2f7d0a8d2","html_url":"https://github.com/mattphillips/jest-expect-message","commit_stats":{"total_commits":45,"total_committers":7,"mean_commits":6.428571428571429,"dds":"0.15555555555555556","last_synced_commit":"47de3e267459030ff07165ae93ebb0c1a4dbf8e8"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattphillips%2Fjest-expect-message","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattphillips%2Fjest-expect-message/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattphillips%2Fjest-expect-message/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattphillips%2Fjest-expect-message/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattphillips","download_url":"https://codeload.github.com/mattphillips/jest-expect-message/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319720,"owners_count":22051075,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["custom","expect","jest","message","test"],"created_at":"2024-07-31T17:01:19.671Z","updated_at":"2025-05-15T17:05:58.809Z","avatar_url":"https://github.com/mattphillips.png","language":"JavaScript","funding_links":["https://github.com/sponsors/mattphillips"],"categories":["JavaScript","Packages"],"sub_categories":["Library extensions"],"readme":"\u003cdiv align=\"center\"\u003e\n\u003ch1\u003ejest-expect-message\u003c/h1\u003e\n\n🃏🗯\n\nAdd custom message to Jest expects\n\n\u003c/div\u003e\n\n\u003chr /\u003e\n\n[![Build Status](https://img.shields.io/github/workflow/status/mattphillips/jest-expect-message/GitHub%20CI/main?style=flat-square)](https://github.com/mattphillips/jest-expect-message/actions/workflows/ci.yaml)\n[![Code Coverage](https://img.shields.io/codecov/c/github/mattphillips/jest-expect-message.svg?style=flat-square)](https://codecov.io/github/mattphillips/jest-expect-message)\n[![version](https://img.shields.io/npm/v/jest-expect-message.svg?style=flat-square)](https://www.npmjs.com/package/jest-expect-message)\n[![downloads](https://img.shields.io/npm/dm/jest-expect-message.svg?style=flat-square)](http://npm-stat.com/charts.html?package=jest-expect-message\u0026from=2017-09-14)\n[![MIT License](https://img.shields.io/npm/l/jest-expect-message.svg?style=flat-square)](https://github.com/mattphillips/jest-expect-message/blob/master/LICENSE)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n[![Roadmap](https://img.shields.io/badge/%F0%9F%93%94-roadmap-CD9523.svg?style=flat-square)](https://github.com/mattphillips/jest-expect-message/blob/master/docs/ROADMAP.md)\n[![Examples](https://img.shields.io/badge/%F0%9F%92%A1-examples-ff615b.svg?style=flat-square)](https://github.com/mattphillips/jest-expect-message/blob/master/docs/EXAMPLES.md)\n\n## Problem\n\nIn many testing libraries it is possible to supply a custom message for a given expectation, this is currently not\npossible in Jest.\n\nFor example:\n\n```js\ntest('returns 2 when adding 1 and 1', () =\u003e {\n  expect(1 + 1, 'Woah this should be 2!').toBe(3);\n});\n```\n\nThis will throw the following error in Jest:\n\n```sh\nExpect takes at most one argument.\n```\n\n## Solution\n\n`jest-expect-message` allows you to call `expect` with a second argument of a `String` message.\n\nFor example the same test as above:\n\n```js\ntest('returns 2 when adding 1 and 1', () =\u003e {\n  expect(1 + 1, 'Woah this should be 2!').toBe(3);\n});\n```\n\nWith `jest-expect-message` this will fail with your custom error message:\n\n```sh\n  ● returns 2 when adding 1 and 1\n\n    Custom message:\n      Woah this should be 2!\n\n    expect(received).toBe(expected) // Object.is equality\n\n    Expected: 3\n    Received: 2\n```\n\n## Installation\n\nWith npm:\n\n```sh\nnpm install --save-dev jest-expect-message\n```\n\nWith yarn:\n\n```sh\nyarn add -D jest-expect-message\n```\n\n## Setup\n\nAdd `jest-expect-message` to your Jest `setupFilesAfterEnv` configuration.\n[See for help](https://jestjs.io/docs/en/next/configuration#setupfilesafterenv-array)\n\n### Jest v24+\n\n```json\n\"jest\": {\n  \"setupFilesAfterEnv\": [\"jest-expect-message\"]\n}\n```\n\n### Jest v23-\n\n```json\n\"jest\": {\n  \"setupTestFrameworkScriptFile\": \"jest-expect-message\"\n}\n```\n\nIf you have a custom setup file and want to use this library then add the following to your setup file.\n\n```js\nimport 'jest-expect-message';\n```\n\n### Configure Typescript\n\nAdd the following entry to your tsconfig to enable Typescript support.\n\n```json\n  \"files\": [\"node_modules/jest-expect-message/types/index.d.ts\"],\n```\n\n#### Example\n\nCustom message [example](/example) with typescript\n\n### Configure ESlint\n\n```json\n\"rules\": {\n  \"jest/valid-expect\": [\n    \"error\",\n    {\n      \"maxArgs\": 2\n    }\n  ]\n}\n```\n\n## Usage\n\n- `expect(actual, message, options?)`\n  - `actual`: The value you would normally pass into an `expect` to assert against with a given matcher.\n  - `message`: String, the custom message you want to be printed should the `expect` fail.\n  - `options`: An optional object that controls what is shown as part of the custom message.\n    - `showPrefix: boolean`: If `false` will not show the `Custom message:` prefix. Default: `true`\n    - `showMatcherMessage: boolean`: If `false` will not show the matchers original error message. Default: `true`\n    - `showStack: boolean`: If `false` will not show the matchers stack trace. Default: `true`\n\n```js\ntest('returns 2 when adding 1 and 1', () =\u003e {\n  expect(1 + 1, 'Woah this should be 2!').toBe(3);\n});\n// ↓ ↓ ↓ ↓ ↓ ↓\n/*\n  ● returns 2 when adding 1 and 1\n\n    Custom message:\n      Woah this should be 2!\n\n    expect(received).toBe(expected) // Object.is equality\n\n    Expected: 3\n    Received: 2\n\n  1 |   test('returns 2 when adding 1 and 1', () =\u003e {\n\u003e 2 |     expect(1 + 1, 'Woah this should be 2!').toBe(3);\n    |                                             ^\n  3 |   });\n*/\n```\n\n### showPrefix: `false`\n\n```js\ntest('returns 2 when adding 1 and 1', () =\u003e {\n  expect(1 + 1, 'Woah this should be 2!', { showPrefix: false }).toBe(3);\n});\n// ↓ ↓ ↓ ↓ ↓ ↓\n/*\n  ● returns 2 when adding 1 and 1\n\n    Woah this should be 2!\n\n    expect(received).toBe(expected) // Object.is equality\n\n    Expected: 3\n    Received: 2\n\n  1 |   test('returns 2 when adding 1 and 1', () =\u003e {\n\u003e 2 |     expect(1 + 1, 'Woah this should be 2!', { showPrefix: false }).toBe(3);\n    |                                                                    ^\n  3 |   });\n*/\n```\n\n### showMatcherMessage: `false`\n\n```js\ntest('returns 2 when adding 1 and 1', () =\u003e {\n  expect(1 + 1, 'Woah this should be 2!', { showMatcherMessage: false }).toBe(3);\n});\n// ↓ ↓ ↓ ↓ ↓ ↓\n/*\n  ● returns 2 when adding 1 and 1\n\n    Custom message:\n      Woah this should be 2!\n\n  1 |   test('returns 2 when adding 1 and 1', () =\u003e {\n\u003e 2 |     expect(1 + 1, 'Woah this should be 2!', { showMatcherMessage: false }).toBe(3);\n    |                                                                            ^\n  3 |   });\n*/\n```\n\n### showStack: `false`\n\n```js\ntest('returns 2 when adding 1 and 1', () =\u003e {\n  expect(1 + 1, 'Woah this should be 2!', { showStack: false }).toBe(3);\n});\n// ↓ ↓ ↓ ↓ ↓ ↓\n/*\n  ● returns 2 when adding 1 and 1\n\n    Custom message:\n      Woah this should be 2!\n\n    expect(received).toBe(expected) // Object.is equality\n\n    Expected: 3\n    Received: 2\n*/\n```\n\n## LICENSE\n\n[MIT](/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattphillips%2Fjest-expect-message","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattphillips%2Fjest-expect-message","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattphillips%2Fjest-expect-message/lists"}