Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(expect): always show custom message #6217

Merged
merged 14 commits into from
Dec 17, 2024

Conversation

eryue0220
Copy link
Contributor

This pr is to solve #6206

@eryue0220 eryue0220 requested a review from kt3k as a code owner November 28, 2024 08:07
Copy link

codecov bot commented Nov 28, 2024

Codecov Report

Attention: Patch coverage is 92.07921% with 24 lines in your changes missing coverage. Please review.

Project coverage is 96.32%. Comparing base (cc9a7c0) to head (1e6c9d8).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
expect/_matchers.ts 91.11% 23 Missing ⚠️
expect/_assert_not_equals.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6217      +/-   ##
==========================================
- Coverage   96.49%   96.32%   -0.17%     
==========================================
  Files         536      543       +7     
  Lines       41179    41598     +419     
  Branches     6175     6314     +139     
==========================================
+ Hits        39735    40071     +336     
- Misses       1401     1485      +84     
+ Partials       43       42       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kt3k kt3k changed the title feat: add custom message fix(expect): always show custom message Nov 29, 2024
Comment on lines 92 to 93
context.customMessage ??
`Expected the value not to be close to ${expected} (using ${numDigits} digits), but it is`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this part should be something like:

const defaultMessage = `Expected the value not to be close to ${expected} (using ${numDigits} digits), but it is`
throw new AssertionError(
  context.customMessage ? `${context.customMessage}: ${defaultMessage}` : defaultMessage
);

Vitest, for example, shows the custom message like the above.

In Vitest:

expect(42, "custom message").toEqual(43);

This assertion error shows the message like:

AssertionError: custom message: expected 42 to deeply equal 43

- Expected
+ Received

- 43
+ 42

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I missed this message. Sorry for the delay!

@github-actions github-actions bot added the assert label Dec 1, 2024
@eryue0220 eryue0220 marked this pull request as draft December 1, 2024 23:14
@eryue0220 eryue0220 marked this pull request as ready for review December 15, 2024 02:29
@github-actions github-actions bot removed the assert label Dec 17, 2024
@kt3k
Copy link
Member

kt3k commented Dec 17, 2024

I vendored assertIsError to expect/ because the suggested change was not desired for @std/assert/is-error.

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@kt3k kt3k merged commit 5d9d87c into denoland:main Dec 17, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants