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: BigInt Support #8382

Merged
merged 52 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
1941be0
feat(jest-get-type) include bigint
JoshRosenstein Apr 25, 2019
d39a157
(jest-matcher-utils) add ensureActualIsNumberOrBigInit
JoshRosenstein Apr 26, 2019
16a2312
(expect) add biginit support
JoshRosenstein Apr 26, 2019
3ccbce4
Revert gettype to ifelse
JoshRosenstein Apr 26, 2019
2995d69
Add tests mixing numbers and bigint
JoshRosenstein Apr 26, 2019
ff21d21
bigDumbTypo
JoshRosenstein Apr 26, 2019
4128975
babel-plugin-jest-hoist add to whitelist
JoshRosenstein Apr 26, 2019
2488c34
Wrap BigInt Tests with guard
JoshRosenstein Apr 26, 2019
9c68a16
temp fix test suite must contain at least one test
JoshRosenstein Apr 26, 2019
3e33530
remove MatchingSnapshot tests due to unsupported env having obsoletes
JoshRosenstein Apr 26, 2019
50b3bb4
remove unnecessary bigint check in equals
JoshRosenstein Apr 29, 2019
cde6327
Remove ensure*NumbersOrBigInt, include BigInt in originals, add `or b…
JoshRosenstein Apr 29, 2019
8e0656a
Update snapshots with new error message `number or bigint`
JoshRosenstein Apr 29, 2019
d1e1b88
add bigint support to toBeCloseTo, replace ensureNumbersOrBigInt to e…
JoshRosenstein Apr 29, 2019
1a2ff60
tests(expect) remove temp_test, add bigint tests to matchers.test
JoshRosenstein Apr 29, 2019
0c594cf
tests(jest-matcher-utils) remove temp_tests, add bigint tests to inde…
JoshRosenstein Apr 29, 2019
b122b02
Update CHANGELOG.md
JoshRosenstein Apr 29, 2019
c640ec3
Merge branch 'master' into BigInt
JoshRosenstein Apr 29, 2019
f5cec2a
Update CHANGELOG.md
JoshRosenstein Apr 30, 2019
5bf3acc
(babel-preset-jest)-add @babel/plugin-syntax-bigint
JoshRosenstein Apr 30, 2019
be5cbb6
Add tests for bigint syntax
JoshRosenstein Apr 30, 2019
8c1d55c
Update CHANGELOG.md
JoshRosenstein Apr 30, 2019
3459c44
:rage2: :abc:
JoshRosenstein Apr 30, 2019
592d6f3
Checking if node6 breaks with lookup
JoshRosenstein Apr 30, 2019
c2c771a
Revert "Checking if node6 breaks with lookup"
JoshRosenstein Apr 30, 2019
fb6655d
Revert "Add tests for bigint syntax"
JoshRosenstein Apr 30, 2019
0646729
Update CHANGELOG.md
pedrottimark Apr 30, 2019
9390440
Remove Default Precision Value and update error msg via code review
JoshRosenstein May 1, 2019
52d110d
Replace ensureExpectedIsNumber with ensureExpectedIsNonNegativeIntege…
JoshRosenstein May 1, 2019
5430e1a
Update Matchers interface
JoshRosenstein May 1, 2019
42e4e89
Revert Bigint Support for 'toBeCloseTo'
JoshRosenstein May 1, 2019
67d1ad8
Update CHANGELOG.md
JoshRosenstein May 1, 2019
aba6474
pedrottimark's CR fixes in tests :eyes: :dart:
JoshRosenstein May 1, 2019
b4884f5
Merge branch 'master' into BigInt
JoshRosenstein May 5, 2019
c4aea47
Merge remote-tracking branch 'upstream/master' into BigInt
JoshRosenstein May 13, 2019
f2a5745
Update CHANGELOG.md
JoshRosenstein May 13, 2019
99642be
Merge branch 'master' into BigInt
thymikee Jun 14, 2019
f0d73f8
Merge commit '1749aeab92e33fe1ae65196c75aebd2d1f366ab2' into BigInt
SimenB Sep 1, 2019
0bdddfd
Merge commit 'b64d35d127ba41a8233ded35a52a9a70981d9d53' into BigInt
SimenB Sep 1, 2019
d22ed48
Merge commit 'b2c9fe3726d81c7ea6d71115352f177afd6210ba' into BigInt
SimenB Sep 1, 2019
46d64de
Merge commit '798891208e752e084c7935e2e52e0f765a758c1e' into BigInt
SimenB Sep 1, 2019
1d9e41a
Merge commit 'a1e30075ca60fb720ae1ba9a66ba1e4837c67428' into BigInt
SimenB Sep 1, 2019
e8d9411
Merge commit '88ccda0910c83b92bcb5671dc9b0de94e5250054' into BigInt
SimenB Sep 1, 2019
615b2c4
Merge branch 'master' into BigInt
SimenB Sep 1, 2019
6164740
move changelog entries
SimenB Sep 1, 2019
ad3c832
fix changelog formatting
SimenB Sep 1, 2019
c30ae9c
Delete unnecessary disable of eslint rules
pedrottimark Sep 3, 2019
de4d01c
Update ExpectAPI.md
pedrottimark Sep 3, 2019
0e2ef7d
Update CHANGELOG.md
pedrottimark Sep 3, 2019
007919d
Edit ExpectAPI.md
pedrottimark Sep 4, 2019
2d026e9
Merge branch 'master' into BigInt
SimenB Sep 6, 2019
89b1538
Merge branch 'master' into BigInt
SimenB Sep 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ module.exports = {
],
'import/order': 'error',
'no-dupe-class-members': 'off',
// ts handles this check for us, also eslint does not include Bigint
'no-undef': 'off',
'no-unused-vars': 'off',
// ts handles this check for us, also eslint does not include bigint
'valid-typeof': 'off',
Copy link
Contributor

Choose a reason for hiding this comment

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

valid-typeof includes bigint starting in 6.0.0-rc.0

Copy link
Member

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?

},
},
// to make it more suitable for running on code examples in docs/ folder
Expand Down
1 change: 1 addition & 0 deletions packages/jest-get-type/src/__tests__/getType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ describe('.getType()', () => {
test('map', () => expect(getType(new Map())).toBe('map'));
test('set', () => expect(getType(new Set())).toBe('set'));
test('date', () => expect(getType(new Date())).toBe('date'));
test('bigint', () => expect(getType(BigInt(1))).toBe('bigint'));
});
55 changes: 28 additions & 27 deletions packages/jest-get-type/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

type ValueType =
| 'array'
| 'bigint'
| 'boolean'
| 'function'
| 'null'
Expand All @@ -23,6 +24,7 @@ type ValueType =
const PRIMITIVES = new Set<ValueType>([
'string',
'number',
'bigint',
'boolean',
'null',
'undefined',
Expand All @@ -32,35 +34,34 @@ const PRIMITIVES = new Set<ValueType>([
// get the type of a value with handling the edge cases like `typeof []`
// and `typeof null`
function getType(value: unknown): ValueType {
if (value === undefined) {
return 'undefined';
} else if (value === null) {
return 'null';
} else if (Array.isArray(value)) {
return 'array';
} else if (typeof value === 'boolean') {
return 'boolean';
} else if (typeof value === 'function') {
return 'function';
} else if (typeof value === 'number') {
return 'number';
} else if (typeof value === 'string') {
return 'string';
} else if (typeof value === 'object') {
if (value != null) {
if (value.constructor === RegExp) {
return 'regexp';
} else if (value.constructor === Map) {
return 'map';
} else if (value.constructor === Set) {
return 'set';
} else if (value.constructor === Date) {
return 'date';
if (value === null) return 'null';
switch (typeof value) {
case 'undefined':
case 'boolean':
case 'function':
case 'number':
case 'string':
case 'symbol':
case 'bigint': {
return typeof value;
}
case 'object': {
const objectType = Object.prototype.toString
.call(value)
.slice(8, -1)
.toLowerCase();

switch (objectType) {
case 'array':
case 'object':
case 'set':
case 'regexp':
case 'map':
case 'date': {
return objectType;
JoshRosenstein marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
return 'object';
} else if (typeof value === 'symbol') {
return 'symbol';
}

throw new Error(`value of unknown type: ${value}`);
Expand Down