Skip to content

fix: make expect(..., message) consistent as error message prefix#10068

Merged
sheremet-va merged 12 commits intovitest-dev:mainfrom
hi-ogawa:fix-make-expect-message-consistent
Apr 7, 2026
Merged

fix: make expect(..., message) consistent as error message prefix#10068
sheremet-va merged 12 commits intovitest-dev:mainfrom
hi-ogawa:fix-make-expect-message-consistent

Conversation

@hi-ogawa
Copy link
Copy Markdown
Collaborator

@hi-ogawa hi-ogawa commented Apr 5, 2026

Description

Minor behavior nit. Current behavior is:

expect(1, 'custom').toBe(2)
// AssertionError: custom: expected 1 to be 2 // Object.is equality

expect('bar', 'custom').toBeFoo()
// Error: custom

expect('value', 'custom').toMatchSnapshot()
// Error: Snapshot `...` mismatched

expect({ value: 1 }, 'custom').toMatchSnapshot({
  value: expect.any(String),
})
// Error: custom

This PR aligns custom matcher and built-in snapshot behavior to follow Chai style:

expect(1, 'custom').toBe(2)
// AssertionError: custom: expected 1 to be 2 // Object.is equality

expect('bar', 'custom').toBeFoo()
// Error: custom: <matcher-generated-message>

expect('value', 'custom').toMatchSnapshot()
// Error: custom: Snapshot `...` mismatched

expect({ value: 1 }, 'custom').toMatchSnapshot({
  value: expect.any(String),
})
// Error: custom: Snapshot properties mismatched

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 5, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit ba9fd72
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69d2053af16eae00088a41ea
😎 Deploy Preview https://deploy-preview-10068--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@hi-ogawa hi-ogawa marked this pull request as ready for review April 5, 2026 08:14
@sheremet-va
Copy link
Copy Markdown
Member

Is this a breaking change? The message in toThrowInlineSnapshot seems to change and I'm not sure if it's a valid pattern outside of Vitest's monorepo

@hi-ogawa
Copy link
Copy Markdown
Collaborator Author

hi-ogawa commented Apr 5, 2026

I don't think this is a breaking change. I'd consider users catching and probing assertion error content is in a same territory as probing reporter output.

@hi-ogawa hi-ogawa added maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control and removed maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control labels Apr 7, 2026
@hi-ogawa hi-ogawa added maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control and removed maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control labels Apr 7, 2026
@sheremet-va sheremet-va merged commit a1b5f0f into vitest-dev:main Apr 7, 2026
17 of 18 checks passed
@hi-ogawa hi-ogawa deleted the fix-make-expect-message-consistent branch April 8, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants