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
Conversation
✔️ 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 |
def('toBeGreaterThan', function(expected: number | bigint) { | ||
const actual = this._obj | ||
if (typeof actual !== 'number' && typeof actual !== 'bigint') { | ||
return this.assert( |
There was a problem hiding this comment.
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
- Throw TypeError
- Move it to some helper function to reuse in other assertions
- Rewrite to something like:
assertTypes(expected, 'expected', ['number', 'bigint'])
assertTypes(actual, 'received', ['number', 'bigint']) // throws Recieved values must be type or type, received "type"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job 👍
packages/vitest/src/index.ts
Outdated
toBeLessThan(num: number): void | ||
toBeLessThanOrEqual(num: number): void |
There was a problem hiding this comment.
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?
There was a problem hiding this 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.
Fixed
toBeGreaterThan
andtoBeGreaterThanOrEqual
support forBigInt
, which was added in ES2020 to follow jest.https://jestjs.io/docs/expect#tobegreaterthannumber--bigint