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

feat: support BigInt for jest assertions #742

Merged
merged 8 commits into from Feb 13, 2022

Conversation

togami2864
Copy link
Contributor

Fixed toBeGreaterThan and toBeGreaterThanOrEqual support for BigInt, which was added in ES2020 to follow jest.
https://jestjs.io/docs/expect#tobegreaterthannumber--bigint

@netlify
Copy link

netlify bot commented Feb 12, 2022

✔️ Deploy Preview for vitest-dev ready!

🔨 Explore the source changes: dd68bf9

🔍 Inspect the deploy log: https://app.netlify.com/sites/vitest-dev/deploys/6208e69ccf19f800073241b6

😎 Browse the preview: https://deploy-preview-742--vitest-dev.netlify.app

@antfu antfu changed the title [Fix] Support BigInt for jest assertions fix: support BigInt for jest assertions Feb 12, 2022
@antfu antfu changed the title fix: support BigInt for jest assertions feat: support BigInt for jest assertions Feb 12, 2022
def('toBeGreaterThan', function(expected: number | bigint) {
const actual = this._obj
if (typeof actual !== 'number' && typeof actual !== 'bigint') {
return this.assert(
Copy link
Member

Choose a reason for hiding this comment

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

Not sure about this use of assert

It's not actually an AssertionError, since no assertion was actually performed bc the input was wrong. Maybe we can

  1. Throw TypeError
  2. Move it to some helper function to reuse in other assertions
  3. Rewrite to something like:
assertTypes(expected, 'expected', ['number', 'bigint'])
assertTypes(actual, 'received', ['number', 'bigint']) // throws Recieved values must be type or type, received "type"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Display the message like this when a type error occurred.

スクリーンショット 2022-02-13 17 56 08

Copy link
Member

Choose a reason for hiding this comment

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

Good job 👍

Comment on lines 89 to 90
toBeLessThan(num: number): void
toBeLessThanOrEqual(num: number): void
Copy link
Member

Choose a reason for hiding this comment

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

Great PR! toBeLessThan and toBeLessThanOrEqual should also be number | bigint. Would you like to modify them as part of this PR?

Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

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

Looks awesome! Thanks for also implementing support for the rest of the API.

@patak-dev patak-dev merged commit d1df0e0 into vitest-dev:main Feb 13, 2022
chaii3 pushed a commit to chaii3/vitest that referenced this pull request May 13, 2022
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.

None yet

3 participants