-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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: BigInt Support #8382
Merged
Merged
feat: BigInt Support #8382
Changes from 10 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
1941be0
feat(jest-get-type) include bigint
JoshRosenstein d39a157
(jest-matcher-utils) add ensureActualIsNumberOrBigInit
JoshRosenstein 16a2312
(expect) add biginit support
JoshRosenstein 3ccbce4
Revert gettype to ifelse
JoshRosenstein 2995d69
Add tests mixing numbers and bigint
JoshRosenstein ff21d21
bigDumbTypo
JoshRosenstein 4128975
babel-plugin-jest-hoist add to whitelist
JoshRosenstein 2488c34
Wrap BigInt Tests with guard
JoshRosenstein 9c68a16
temp fix test suite must contain at least one test
JoshRosenstein 3e33530
remove MatchingSnapshot tests due to unsupported env having obsoletes
JoshRosenstein 50b3bb4
remove unnecessary bigint check in equals
JoshRosenstein cde6327
Remove ensure*NumbersOrBigInt, include BigInt in originals, add `or b…
JoshRosenstein 8e0656a
Update snapshots with new error message `number or bigint`
JoshRosenstein d1e1b88
add bigint support to toBeCloseTo, replace ensureNumbersOrBigInt to e…
JoshRosenstein 1a2ff60
tests(expect) remove temp_test, add bigint tests to matchers.test
JoshRosenstein 0c594cf
tests(jest-matcher-utils) remove temp_tests, add bigint tests to inde…
JoshRosenstein b122b02
Update CHANGELOG.md
JoshRosenstein c640ec3
Merge branch 'master' into BigInt
JoshRosenstein f5cec2a
Update CHANGELOG.md
JoshRosenstein 5bf3acc
(babel-preset-jest)-add @babel/plugin-syntax-bigint
JoshRosenstein be5cbb6
Add tests for bigint syntax
JoshRosenstein 8c1d55c
Update CHANGELOG.md
JoshRosenstein 3459c44
:rage2: :abc:
JoshRosenstein 592d6f3
Checking if node6 breaks with lookup
JoshRosenstein c2c771a
Revert "Checking if node6 breaks with lookup"
JoshRosenstein fb6655d
Revert "Add tests for bigint syntax"
JoshRosenstein 0646729
Update CHANGELOG.md
pedrottimark 9390440
Remove Default Precision Value and update error msg via code review
JoshRosenstein 52d110d
Replace ensureExpectedIsNumber with ensureExpectedIsNonNegativeIntege…
JoshRosenstein 5430e1a
Update Matchers interface
JoshRosenstein 42e4e89
Revert Bigint Support for 'toBeCloseTo'
JoshRosenstein 67d1ad8
Update CHANGELOG.md
JoshRosenstein aba6474
pedrottimark's CR fixes in tests :eyes: :dart:
JoshRosenstein b4884f5
Merge branch 'master' into BigInt
JoshRosenstein c4aea47
Merge remote-tracking branch 'upstream/master' into BigInt
JoshRosenstein f2a5745
Update CHANGELOG.md
JoshRosenstein 99642be
Merge branch 'master' into BigInt
thymikee f0d73f8
Merge commit '1749aeab92e33fe1ae65196c75aebd2d1f366ab2' into BigInt
SimenB 0bdddfd
Merge commit 'b64d35d127ba41a8233ded35a52a9a70981d9d53' into BigInt
SimenB d22ed48
Merge commit 'b2c9fe3726d81c7ea6d71115352f177afd6210ba' into BigInt
SimenB 46d64de
Merge commit '798891208e752e084c7935e2e52e0f765a758c1e' into BigInt
SimenB 1d9e41a
Merge commit 'a1e30075ca60fb720ae1ba9a66ba1e4837c67428' into BigInt
SimenB e8d9411
Merge commit '88ccda0910c83b92bcb5671dc9b0de94e5250054' into BigInt
SimenB 615b2c4
Merge branch 'master' into BigInt
SimenB 6164740
move changelog entries
SimenB ad3c832
fix changelog formatting
SimenB c30ae9c
Delete unnecessary disable of eslint rules
pedrottimark de4d01c
Update ExpectAPI.md
pedrottimark 0e2ef7d
Update CHANGELOG.md
pedrottimark 007919d
Edit ExpectAPI.md
pedrottimark 2d026e9
Merge branch 'master' into BigInt
SimenB 89b1538
Merge branch 'master' into BigInt
SimenB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,257 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
|
||
/* global BigInt */ | ||
|
||
const {stringify} = require('jest-matcher-utils'); | ||
|
||
const chalk = require('chalk'); | ||
const jestExpect = require('../'); | ||
|
||
const chalkEnabled = chalk.enabled; | ||
|
||
beforeAll(() => { | ||
chalk.enabled = true; | ||
}); | ||
|
||
afterAll(() => { | ||
chalk.enabled = chalkEnabled; | ||
}); | ||
|
||
describe('BigInt', () => { | ||
test('TEMP HAPPY JEST', () => { | ||
expect(1).toBe(1); | ||
}); | ||
|
||
/* global BigInt */ | ||
if (typeof BigInt === 'function') { | ||
describe('.toBe()', () => { | ||
it('does not throw', () => { | ||
jestExpect(BigInt(1)).not.toBe(BigInt(2)); | ||
jestExpect(BigInt(1)).toBe(BigInt(1)); | ||
}); | ||
|
||
[[BigInt(1), BigInt(2)]].forEach(([a, b]) => { | ||
it(`fails for: ${stringify(a)} and ${stringify(b)}`, () => { | ||
expect(() => jestExpect(a).toBe(b)).toThrow(); | ||
}); | ||
}); | ||
|
||
[BigInt(1)].forEach(v => { | ||
it(`fails for '${stringify(v)}' with '.not'`, () => { | ||
expect(() => jestExpect(v).not.toBe(v)).toThrow(); | ||
}); | ||
}); | ||
}); | ||
describe('.toEqual()', () => { | ||
[[BigInt(1), BigInt(2)]].forEach(([a, b]) => { | ||
test(`{pass: false} expect(${stringify(a)}).toEqual(${stringify( | ||
b, | ||
)})`, () => { | ||
expect(() => jestExpect(a).toEqual(b)).toThrow(); | ||
jestExpect(a).not.toEqual(b); | ||
}); | ||
}); | ||
|
||
[[BigInt(1), BigInt(1)]].forEach(([a, b]) => { | ||
test(`{pass: true} expect(${stringify(a)}).not.toEqual(${stringify( | ||
b, | ||
)})`, () => { | ||
jestExpect(a).toEqual(b); | ||
expect(() => jestExpect(a).not.toEqual(b)).toThrow(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('.toBeTruthy(), .toBeFalsy()', () => { | ||
[BigInt(1)].forEach(v => { | ||
test(`'${stringify(v)}' is truthy`, () => { | ||
jestExpect(v).toBeTruthy(); | ||
jestExpect(v).not.toBeFalsy(); | ||
|
||
expect(() => jestExpect(v).not.toBeTruthy()).toThrow(); | ||
|
||
expect(() => jestExpect(v).toBeFalsy()).toThrow(); | ||
}); | ||
}); | ||
|
||
[BigInt(0)].forEach(v => { | ||
test(`'${stringify(v)}' is falsy`, () => { | ||
jestExpect(v).toBeFalsy(); | ||
jestExpect(v).not.toBeTruthy(); | ||
|
||
expect(() => jestExpect(v).toBeTruthy()).toThrow(); | ||
|
||
expect(() => jestExpect(v).not.toBeFalsy()).toThrow(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('.toBeDefined(), .toBeUndefined()', () => { | ||
[BigInt(1)].forEach(v => { | ||
test(`'${stringify(v)}' is defined`, () => { | ||
jestExpect(v).toBeDefined(); | ||
jestExpect(v).not.toBeUndefined(); | ||
|
||
expect(() => jestExpect(v).not.toBeDefined()).toThrow(); | ||
|
||
expect(() => jestExpect(v).toBeUndefined()).toThrow(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe( | ||
'.toBeGreaterThan(), .toBeLessThan(), ' + | ||
'.toBeGreaterThanOrEqual(), .toBeLessThanOrEqual()', | ||
() => { | ||
[[BigInt(1), BigInt(2)]].forEach(([small, big]) => { | ||
it(`{pass: true} expect(${small}).toBeLessThan(${big})`, () => { | ||
jestExpect(small).toBeLessThan(big); | ||
}); | ||
|
||
it(`{pass: false} expect(${big}).toBeLessThan(${small})`, () => { | ||
jestExpect(big).not.toBeLessThan(small); | ||
}); | ||
|
||
it(`{pass: true} expect(${big}).toBeGreaterThan(${small})`, () => { | ||
jestExpect(big).toBeGreaterThan(small); | ||
}); | ||
|
||
it(`{pass: false} expect(${small}).toBeGreaterThan(${big})`, () => { | ||
jestExpect(small).not.toBeGreaterThan(big); | ||
}); | ||
|
||
it(`{pass: true} expect(${small}).toBeLessThanOrEqual(${big})`, () => { | ||
jestExpect(small).toBeLessThanOrEqual(big); | ||
}); | ||
|
||
it(`{pass: false} expect(${big}).toBeLessThanOrEqual(${small})`, () => { | ||
jestExpect(big).not.toBeLessThanOrEqual(small); | ||
}); | ||
|
||
it(`{pass: true} expect(${big}).toBeGreaterThanOrEqual(${small})`, () => { | ||
jestExpect(big).toBeGreaterThanOrEqual(small); | ||
}); | ||
|
||
it(`{pass: false} expect(${small}).toBeGreaterThanOrEqual(${big})`, () => { | ||
jestExpect(small).not.toBeGreaterThanOrEqual(big); | ||
}); | ||
|
||
it(`throws: [${small}, ${big}]`, () => { | ||
expect(() => jestExpect(small).toBeGreaterThan(big)).toThrow(); | ||
|
||
expect(() => jestExpect(small).not.toBeLessThan(big)).toThrow(); | ||
|
||
expect(() => jestExpect(big).not.toBeGreaterThan(small)).toThrow(); | ||
|
||
expect(() => jestExpect(big).toBeLessThan(small)).toThrow(); | ||
|
||
expect(() => | ||
jestExpect(small).toBeGreaterThanOrEqual(big), | ||
).toThrow(); | ||
|
||
expect(() => | ||
jestExpect(small).not.toBeLessThanOrEqual(big), | ||
).toThrow(); | ||
|
||
expect(() => | ||
jestExpect(big).not.toBeGreaterThanOrEqual(small), | ||
).toThrow(); | ||
|
||
expect(() => jestExpect(big).toBeLessThanOrEqual(small)).toThrow(); | ||
}); | ||
}); | ||
|
||
[[BigInt(1), BigInt(1)]].forEach(([n1, n2]) => { | ||
test(`equal numbers: [${n1}, ${n2}]`, () => { | ||
jestExpect(n1).toBeGreaterThanOrEqual(n2); | ||
jestExpect(n1).toBeLessThanOrEqual(n2); | ||
|
||
expect(() => | ||
jestExpect(n1).not.toBeGreaterThanOrEqual(n2), | ||
).toThrow(); | ||
|
||
expect(() => jestExpect(n1).not.toBeLessThanOrEqual(n2)).toThrow(); | ||
}); | ||
}); | ||
}, | ||
); | ||
|
||
describe('.toStrictEqual()', () => { | ||
class TestClassA { | ||
constructor(a, b) { | ||
this.a = a; | ||
this.b = b; | ||
} | ||
} | ||
|
||
it('passes when comparing same type', () => { | ||
expect({ | ||
test: new TestClassA(BigInt(1), BigInt(2)), | ||
}).toStrictEqual({test: new TestClassA(BigInt(1), BigInt(2))}); | ||
}); | ||
|
||
it('matches the expected snapshot when it fails', () => { | ||
expect(() => | ||
jestExpect({ | ||
test: BigInt(2), | ||
}).toStrictEqual({test: new TestClassA(BigInt(1), BigInt(2))}), | ||
).toThrow(); | ||
|
||
expect(() => | ||
jestExpect({ | ||
test: new TestClassA(BigInt(1), BigInt(2)), | ||
}).not.toStrictEqual({test: new TestClassA(BigInt(1), BigInt(2))}), | ||
).toThrow(); | ||
}); | ||
|
||
/* eslint-disable no-sparse-arrays */ | ||
it('passes for matching sparse arrays', () => { | ||
expect([, BigInt(1)]).toStrictEqual([, BigInt(1)]); | ||
}); | ||
|
||
it('does not pass when sparseness of arrays do not match', () => { | ||
expect([, BigInt(1)]).not.toStrictEqual([undefined, BigInt(1)]); | ||
expect([undefined, BigInt(1)]).not.toStrictEqual([, BigInt(1)]); | ||
expect([, , , BigInt(1)]).not.toStrictEqual([, BigInt(1)]); | ||
}); | ||
|
||
it('does not pass when equally sparse arrays have different values', () => { | ||
expect([, BigInt(1)]).not.toStrictEqual([, BigInt(2)]); | ||
}); | ||
/* eslint-enable */ | ||
}); | ||
|
||
describe('Reproduce From #6829', () => { | ||
test('It should accept BigInt("x") way', () => { | ||
const a = BigInt('123456789012345678901234567890'); | ||
jestExpect(typeof a).toEqual('bigint'); | ||
}); | ||
test('It should allow to do equal comparision', () => { | ||
const a = BigInt(2); | ||
jestExpect(a).toEqual(BigInt(2)); | ||
}); | ||
test('It should allow to do greater than comparision', () => { | ||
const a = BigInt(2); | ||
jestExpect(a).toBeGreaterThan(1); | ||
}); | ||
test('It should allow to do greater than or equal comparision', () => { | ||
const a = BigInt(2); | ||
jestExpect(a).toBeGreaterThanOrEqual(2); | ||
}); | ||
test('It should allow to do less than comparision', () => { | ||
const a = BigInt(2); | ||
jestExpect(a).toBeLessThan(3); | ||
}); | ||
test('It should allow to do less than or equal comparision', () => { | ||
const a = BigInt(2); | ||
jestExpect(a).toBeLessThanOrEqual(2); | ||
}); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
valid-typeof
includesbigint
starting in 6.0.0-rc.0There 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.
yeah, we can revert the eslint changes if they no longer cause issues. Makes this PR a bit bigger than it needs to be. you wanna do that?