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
Changes from 4 commits
a17f9ed
c5b6f06
eac30ab
d38b7e0
08f44e0
7dae192
301abc2
dd68bf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,11 +160,61 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => { | |
obj, | ||
) | ||
}) | ||
def('toBeGreaterThan', function(expected: number) { | ||
return this.to.greaterThan(expected) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about this use of It's not actually an
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Good job 👍 |
||
false, | ||
`expected "${actual}" to be a number or bigint`, | ||
`expected "${actual}" to be a number or bigint`, | ||
actual, | ||
expected, | ||
) | ||
} | ||
if (typeof expected !== 'number' && typeof expected !== 'bigint') { | ||
return this.assert( | ||
false, | ||
`expected "${expected}" to be a number or bigint`, | ||
`expected "${expected}" to be a number or bigint`, | ||
actual, | ||
expected, | ||
) | ||
} | ||
return this.assert( | ||
actual > expected, | ||
`expected ${actual} to be above ${expected}`, | ||
`expected ${actual} not to be above ${expected}`, | ||
actual, | ||
expected, | ||
) | ||
}) | ||
def('toBeGreaterThanOrEqual', function(expected: number) { | ||
return this.to.greaterThanOrEqual(expected) | ||
const actual = this._obj | ||
if (typeof actual !== 'number' && typeof actual !== 'bigint') { | ||
return this.assert( | ||
false, | ||
`expected "${actual}" to be a number or bigint`, | ||
`expected "${actual}" to be a number or bigint`, | ||
actual, | ||
expected, | ||
) | ||
} | ||
if (typeof expected !== 'number' && typeof expected !== 'bigint') { | ||
return this.assert( | ||
false, | ||
`expected "${expected}" to be a number or bigint`, | ||
`expected "${expected}" to be a number or bigint`, | ||
actual, | ||
expected, | ||
) | ||
} | ||
return this.assert( | ||
actual >= expected, | ||
`expected ${actual} to be above ${expected}`, | ||
`expected ${actual} not to be above ${expected}`, | ||
actual, | ||
expected, | ||
) | ||
}) | ||
def('toBeLessThan', function(expected: number) { | ||
return this.to.lessThan(expected) | ||
|
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
andtoBeLessThanOrEqual
should also benumber | bigint
. Would you like to modify them as part of this PR?