From 9d286a65c469a3e10a2d379feebf821799a81ec3 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 19 Oct 2021 08:51:00 +0200 Subject: [PATCH] chore: `BigInt` is always defined, do not conditionally check for it (#11979) --- .eslintrc.js | 3 + CHANGELOG.md | 1 + .../src/__tests__/asymmetricMatchers.test.ts | 2 - .../expect/src/__tests__/matchers.test.js | 406 ++++++++---------- packages/expect/src/asymmetricMatchers.ts | 1 - .../src/__tests__/getType.test.ts | 5 +- .../src/__tests__/isPrimitive.test.ts | 3 +- .../src/__tests__/index.test.ts | 24 +- .../src/__tests__/prettyFormat.test.ts | 35 +- 9 files changed, 216 insertions(+), 264 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 444c0d1924c9..905133b3a923 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -26,6 +26,9 @@ module.exports = { 'plugin:eslint-comments/recommended', 'plugin:prettier/recommended', ], + globals: { + BigInt: 'readonly', + }, overrides: [ { extends: [ diff --git a/CHANGELOG.md b/CHANGELOG.md index a82285e1d682..f9bbade9b88c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Chore & Maintenance +- `[expect]` `BigInt` global is always defined, don't check for its existence at runtime ([#11979](https://github.com/facebook/jest/pull/11979)) - `[jest-config, jest-util]` Use `ci-info` instead of `is-ci` to detect CI environment ([#11973](https://github.com/facebook/jest/pull/11973)) ### Performance diff --git a/packages/expect/src/__tests__/asymmetricMatchers.test.ts b/packages/expect/src/__tests__/asymmetricMatchers.test.ts index 9c9e7b996509..68243087aa7b 100644 --- a/packages/expect/src/__tests__/asymmetricMatchers.test.ts +++ b/packages/expect/src/__tests__/asymmetricMatchers.test.ts @@ -28,7 +28,6 @@ test('Any.asymmetricMatch()', () => { any(Number).asymmetricMatch(1), any(Function).asymmetricMatch(() => {}), any(Boolean).asymmetricMatch(true), - /* global BigInt */ any(BigInt).asymmetricMatch(1n), any(Symbol).asymmetricMatch(Symbol()), any(Object).asymmetricMatch({}), @@ -50,7 +49,6 @@ test('Any.asymmetricMatch() on primitive wrapper classes', () => { any(Function).asymmetricMatch(new Function('() => {}')), // eslint-disable-next-line no-new-wrappers any(Boolean).asymmetricMatch(new Boolean(true)), - /* global BigInt */ any(BigInt).asymmetricMatch(Object(1n)), any(Symbol).asymmetricMatch(Object(Symbol())), ].forEach(test => { diff --git a/packages/expect/src/__tests__/matchers.test.js b/packages/expect/src/__tests__/matchers.test.js index 1e244e6d7d57..6599df72b2b2 100644 --- a/packages/expect/src/__tests__/matchers.test.js +++ b/packages/expect/src/__tests__/matchers.test.js @@ -22,9 +22,6 @@ afterAll(() => { chalk.enabled = chalkEnabled; }); -/* global BigInt */ -const isBigIntDefined = typeof BigInt === 'function'; - it('should throw if passed two arguments', () => { expect(() => jestExpect('foo', 'bar')).toThrow( new Error('Expect takes at most one argument.'), @@ -209,11 +206,9 @@ describe('.toBe()', () => { jestExpect(null).toBe(null); jestExpect(undefined).toBe(undefined); jestExpect(NaN).toBe(NaN); - if (isBigIntDefined) { - jestExpect(BigInt(1)).not.toBe(BigInt(2)); - jestExpect(BigInt(1)).not.toBe(1); - jestExpect(BigInt(1)).toBe(BigInt(1)); - } + jestExpect(BigInt(1)).not.toBe(BigInt(2)); + jestExpect(BigInt(1)).not.toBe(1); + jestExpect(BigInt(1)).toBe(BigInt(1)); }); [ @@ -247,16 +242,14 @@ describe('.toBe()', () => { }); }); - if (isBigIntDefined) { - [ - [BigInt(1), BigInt(2)], - [{a: BigInt(1)}, {a: BigInt(1)}], - ].forEach(([a, b]) => { - it(`fails for: ${stringify(a)} and ${stringify(b)}`, () => { - expect(() => jestExpect(a).toBe(b)).toThrowError('toBe'); - }); + [ + [BigInt(1), BigInt(2)], + [{a: BigInt(1)}, {a: BigInt(1)}], + ].forEach(([a, b]) => { + it(`fails for: ${stringify(a)} and ${stringify(b)}`, () => { + expect(() => jestExpect(a).toBe(b)).toThrowError('toBe'); }); - } + }); [false, 1, 'a', undefined, null, {}, []].forEach(v => { it(`fails for '${stringify(v)}' with '.not'`, () => { @@ -264,13 +257,11 @@ describe('.toBe()', () => { }); }); - if (isBigIntDefined) { - [BigInt(1), BigInt('1')].forEach(v => { - it(`fails for '${stringify(v)}' with '.not'`, () => { - expect(() => jestExpect(v).not.toBe(v)).toThrowError('toBe'); - }); + [BigInt(1), BigInt('1')].forEach(v => { + it(`fails for '${stringify(v)}' with '.not'`, () => { + expect(() => jestExpect(v).not.toBe(v)).toThrowError('toBe'); }); - } + }); it('does not crash on circular references', () => { const obj = {}; @@ -660,19 +651,17 @@ describe('.toEqual()', () => { }); }); - if (isBigIntDefined) { - [ - [BigInt(1), BigInt(2)], - [BigInt(1), 1], - ].forEach(([a, b]) => { - test(`{pass: false} expect(${stringify(a)}).toEqual(${stringify( - b, - )})`, () => { - expect(() => jestExpect(a).toEqual(b)).toThrowError('toEqual'); - jestExpect(a).not.toEqual(b); - }); + [ + [BigInt(1), BigInt(2)], + [BigInt(1), 1], + ].forEach(([a, b]) => { + test(`{pass: false} expect(${stringify(a)}).toEqual(${stringify( + b, + )})`, () => { + expect(() => jestExpect(a).toEqual(b)).toThrowError('toEqual'); + jestExpect(a).not.toEqual(b); }); - } + }); [ [true, true], @@ -868,27 +857,25 @@ describe('.toEqual()', () => { }); }); - if (isBigIntDefined) { + [ + [BigInt(1), BigInt(1)], + [BigInt(0), BigInt('0')], + [[BigInt(1)], [BigInt(1)]], [ - [BigInt(1), BigInt(1)], - [BigInt(0), BigInt('0')], - [[BigInt(1)], [BigInt(1)]], - [ - [BigInt(1), 2], - [BigInt(1), 2], - ], - [Immutable.List([BigInt(1)]), Immutable.List([BigInt(1)])], - [{a: BigInt(99)}, {a: BigInt(99)}], - [new Set([BigInt(1), BigInt(2)]), new Set([BigInt(1), BigInt(2)])], - ].forEach(([a, b]) => { - test(`{pass: true} expect(${stringify(a)}).not.toEqual(${stringify( - b, - )})`, () => { - jestExpect(a).toEqual(b); - expect(() => jestExpect(a).not.toEqual(b)).toThrowError('toEqual'); - }); + [BigInt(1), 2], + [BigInt(1), 2], + ], + [Immutable.List([BigInt(1)]), Immutable.List([BigInt(1)])], + [{a: BigInt(99)}, {a: BigInt(99)}], + [new Set([BigInt(1), BigInt(2)]), new Set([BigInt(1), BigInt(2)])], + ].forEach(([a, b]) => { + test(`{pass: true} expect(${stringify(a)}).not.toEqual(${stringify( + b, + )})`, () => { + jestExpect(a).toEqual(b); + expect(() => jestExpect(a).not.toEqual(b)).toThrowError('toEqual'); }); - } + }); test('assertion error matcherResult property contains matcher name, expected and actual values', () => { const actual = {a: 1}; @@ -1093,18 +1080,16 @@ describe('.toBeTruthy(), .toBeFalsy()', () => { }); }); - if (isBigIntDefined) { - [BigInt(1)].forEach(v => { - test(`'${stringify(v)}' is truthy`, () => { - jestExpect(v).toBeTruthy(); - jestExpect(v).not.toBeFalsy(); + [BigInt(1)].forEach(v => { + test(`'${stringify(v)}' is truthy`, () => { + jestExpect(v).toBeTruthy(); + jestExpect(v).not.toBeFalsy(); - expect(() => jestExpect(v).not.toBeTruthy()).toThrowError('toBeTruthy'); + expect(() => jestExpect(v).not.toBeTruthy()).toThrowError('toBeTruthy'); - expect(() => jestExpect(v).toBeFalsy()).toThrowError('toBeFalsy'); - }); + expect(() => jestExpect(v).toBeFalsy()).toThrowError('toBeFalsy'); }); - } + }); [false, null, NaN, 0, '', undefined].forEach(v => { test(`'${stringify(v)}' is falsy`, () => { @@ -1119,18 +1104,16 @@ describe('.toBeTruthy(), .toBeFalsy()', () => { }); }); - if (isBigIntDefined) { - [BigInt(0)].forEach(v => { - test(`'${stringify(v)}' is falsy`, () => { - jestExpect(v).toBeFalsy(); - jestExpect(v).not.toBeTruthy(); + [BigInt(0)].forEach(v => { + test(`'${stringify(v)}' is falsy`, () => { + jestExpect(v).toBeFalsy(); + jestExpect(v).not.toBeTruthy(); - expect(() => jestExpect(v).toBeTruthy()).toThrowError('toBeTruthy'); + expect(() => jestExpect(v).toBeTruthy()).toThrowError('toBeTruthy'); - expect(() => jestExpect(v).not.toBeFalsy()).toThrowError('toBeFalsy'); - }); + expect(() => jestExpect(v).not.toBeFalsy()).toThrowError('toBeFalsy'); }); - } + }); }); describe('.toBeNaN()', () => { @@ -1187,22 +1170,16 @@ describe('.toBeDefined(), .toBeUndefined()', () => { }); }); - if (isBigIntDefined) { - [BigInt(1)].forEach(v => { - test(`'${stringify(v)}' is defined`, () => { - jestExpect(v).toBeDefined(); - jestExpect(v).not.toBeUndefined(); + [BigInt(1)].forEach(v => { + test(`'${stringify(v)}' is defined`, () => { + jestExpect(v).toBeDefined(); + jestExpect(v).not.toBeUndefined(); - expect(() => jestExpect(v).not.toBeDefined()).toThrowError( - 'toBeDefined', - ); + expect(() => jestExpect(v).not.toBeDefined()).toThrowError('toBeDefined'); - expect(() => jestExpect(v).toBeUndefined()).toThrowError( - 'toBeUndefined', - ); - }); + expect(() => jestExpect(v).toBeUndefined()).toThrowError('toBeUndefined'); }); - } + }); test('undefined is undefined', () => { jestExpect(undefined).toBeUndefined(); @@ -1298,104 +1275,101 @@ describe( }); }); - if (isBigIntDefined) { - test('can compare BigInt to Numbers', () => { - const a = BigInt(2); - jestExpect(a).toBeGreaterThan(1); - jestExpect(a).toBeGreaterThanOrEqual(2); - jestExpect(2).toBeLessThanOrEqual(a); - jestExpect(a).toBeLessThan(3); - jestExpect(a).toBeLessThanOrEqual(2); + test('can compare BigInt to Numbers', () => { + const a = BigInt(2); + jestExpect(a).toBeGreaterThan(1); + jestExpect(a).toBeGreaterThanOrEqual(2); + jestExpect(2).toBeLessThanOrEqual(a); + jestExpect(a).toBeLessThan(3); + jestExpect(a).toBeLessThanOrEqual(2); + }); + [ + [BigInt(1), BigInt(2)], + [BigInt(0x11), BigInt(0x22)], + [-1, BigInt(2)], + ].forEach(([small, big]) => { + it(`{pass: true} expect(${stringify(small)}).toBeLessThan(${stringify( + big, + )})`, () => { + jestExpect(small).toBeLessThan(big); }); - [ - [BigInt(1), BigInt(2)], - [BigInt(0x11), BigInt(0x22)], - [-1, BigInt(2)], - ].forEach(([small, big]) => { - it(`{pass: true} expect(${stringify(small)}).toBeLessThan(${stringify( - big, - )})`, () => { - jestExpect(small).toBeLessThan(big); - }); - - it(`{pass: false} expect(${stringify(big)}).toBeLessThan(${stringify( - small, - )})`, () => { - jestExpect(big).not.toBeLessThan(small); - }); - - it(`{pass: true} expect(${stringify(big)}).toBeGreaterThan(${stringify( - small, - )})`, () => { - jestExpect(big).toBeGreaterThan(small); - }); - - it(`{pass: false} expect(${stringify( - small, - )}).toBeGreaterThan(${stringify(big)})`, () => { - jestExpect(small).not.toBeGreaterThan(big); - }); - - it(`{pass: true} expect(${stringify( - small, - )}).toBeLessThanOrEqual(${stringify(big)})`, () => { - jestExpect(small).toBeLessThanOrEqual(big); - }); - - it(`{pass: false} expect(${stringify( - big, - )}).toBeLessThanOrEqual(${stringify(small)})`, () => { - jestExpect(big).not.toBeLessThanOrEqual(small); - }); - - it(`{pass: true} expect(${stringify( - big, - )}).toBeGreaterThanOrEqual(${stringify(small)})`, () => { - jestExpect(big).toBeGreaterThanOrEqual(small); - }); - - it(`{pass: false} expect(${stringify( - small, - )}).toBeGreaterThanOrEqual(${stringify(big)})`, () => { - jestExpect(small).not.toBeGreaterThanOrEqual(big); - }); - - it(`throws: [${stringify(small)}, ${stringify(big)}]`, () => { - expect(() => jestExpect(small).toBeGreaterThan(big)).toThrowError( - 'toBeGreaterThan', - ); - - expect(() => jestExpect(small).not.toBeLessThan(big)).toThrowError( - 'toBeLessThan', - ); - - expect(() => jestExpect(big).not.toBeGreaterThan(small)).toThrowError( - 'toBeGreaterThan', - ); - - expect(() => jestExpect(big).toBeLessThan(small)).toThrowError( - 'toBeLessThan', - ); - - expect(() => - jestExpect(small).toBeGreaterThanOrEqual(big), - ).toThrowError('toBeGreaterThanOrEqual'); - - expect(() => - jestExpect(small).not.toBeLessThanOrEqual(big), - ).toThrowError('toBeLessThanOrEqual'); - - expect(() => - jestExpect(big).not.toBeGreaterThanOrEqual(small), - ).toThrowError('toBeGreaterThanOrEqual'); - - expect(() => jestExpect(big).toBeLessThanOrEqual(small)).toThrowError( - 'toBeLessThanOrEqual', - ); - }); + it(`{pass: false} expect(${stringify(big)}).toBeLessThan(${stringify( + small, + )})`, () => { + jestExpect(big).not.toBeLessThan(small); }); - } + + it(`{pass: true} expect(${stringify(big)}).toBeGreaterThan(${stringify( + small, + )})`, () => { + jestExpect(big).toBeGreaterThan(small); + }); + + it(`{pass: false} expect(${stringify(small)}).toBeGreaterThan(${stringify( + big, + )})`, () => { + jestExpect(small).not.toBeGreaterThan(big); + }); + + it(`{pass: true} expect(${stringify( + small, + )}).toBeLessThanOrEqual(${stringify(big)})`, () => { + jestExpect(small).toBeLessThanOrEqual(big); + }); + + it(`{pass: false} expect(${stringify( + big, + )}).toBeLessThanOrEqual(${stringify(small)})`, () => { + jestExpect(big).not.toBeLessThanOrEqual(small); + }); + + it(`{pass: true} expect(${stringify( + big, + )}).toBeGreaterThanOrEqual(${stringify(small)})`, () => { + jestExpect(big).toBeGreaterThanOrEqual(small); + }); + + it(`{pass: false} expect(${stringify( + small, + )}).toBeGreaterThanOrEqual(${stringify(big)})`, () => { + jestExpect(small).not.toBeGreaterThanOrEqual(big); + }); + + it(`throws: [${stringify(small)}, ${stringify(big)}]`, () => { + expect(() => jestExpect(small).toBeGreaterThan(big)).toThrowError( + 'toBeGreaterThan', + ); + + expect(() => jestExpect(small).not.toBeLessThan(big)).toThrowError( + 'toBeLessThan', + ); + + expect(() => jestExpect(big).not.toBeGreaterThan(small)).toThrowError( + 'toBeGreaterThan', + ); + + expect(() => jestExpect(big).toBeLessThan(small)).toThrowError( + 'toBeLessThan', + ); + + expect(() => + jestExpect(small).toBeGreaterThanOrEqual(big), + ).toThrowError('toBeGreaterThanOrEqual'); + + expect(() => + jestExpect(small).not.toBeLessThanOrEqual(big), + ).toThrowError('toBeLessThanOrEqual'); + + expect(() => + jestExpect(big).not.toBeGreaterThanOrEqual(small), + ).toThrowError('toBeGreaterThanOrEqual'); + + expect(() => jestExpect(big).toBeLessThanOrEqual(small)).toThrowError( + 'toBeLessThanOrEqual', + ); + }); + }); [ [1, 1], @@ -1418,25 +1392,23 @@ describe( }); }); - if (isBigIntDefined) { - [ - [BigInt(1), BigInt(1)], - [BigInt(Number.MAX_SAFE_INTEGER), BigInt(Number.MAX_SAFE_INTEGER)], - ].forEach(([n1, n2]) => { - test(`equal numbers: [${n1}, ${n2}]`, () => { - jestExpect(n1).toBeGreaterThanOrEqual(n2); - jestExpect(n1).toBeLessThanOrEqual(n2); + [ + [BigInt(1), BigInt(1)], + [BigInt(Number.MAX_SAFE_INTEGER), BigInt(Number.MAX_SAFE_INTEGER)], + ].forEach(([n1, n2]) => { + test(`equal numbers: [${n1}, ${n2}]`, () => { + jestExpect(n1).toBeGreaterThanOrEqual(n2); + jestExpect(n1).toBeLessThanOrEqual(n2); - expect(() => - jestExpect(n1).not.toBeGreaterThanOrEqual(n2), - ).toThrowError('toBeGreaterThanOrEqual'); + expect(() => + jestExpect(n1).not.toBeGreaterThanOrEqual(n2), + ).toThrowError('toBeGreaterThanOrEqual'); - expect(() => jestExpect(n1).not.toBeLessThanOrEqual(n2)).toThrowError( - 'toBeLessThanOrEqual', - ); - }); + expect(() => jestExpect(n1).not.toBeLessThanOrEqual(n2)).toThrowError( + 'toBeLessThanOrEqual', + ); }); - } + }); }, ); @@ -1486,20 +1458,16 @@ describe('.toContain(), .toContainEqual()', () => { }); }); - if (isBigIntDefined) { - [ - [[BigInt(1), BigInt(2), BigInt(3), BigInt(4)], BigInt(1)], - [[1, 2, 3, BigInt(3), 4], BigInt(3)], - ].forEach(([list, v]) => { - it(`'${stringify(list)}' contains '${stringify(v)}'`, () => { - jestExpect(list).toContain(v); - - expect(() => jestExpect(list).not.toContain(v)).toThrowError( - 'toContain', - ); - }); + [ + [[BigInt(1), BigInt(2), BigInt(3), BigInt(4)], BigInt(1)], + [[1, 2, 3, BigInt(3), 4], BigInt(3)], + ].forEach(([list, v]) => { + it(`'${stringify(list)}' contains '${stringify(v)}'`, () => { + jestExpect(list).toContain(v); + + expect(() => jestExpect(list).not.toContain(v)).toThrowError('toContain'); }); - } + }); [ [[1, 2, 3], 4], @@ -1516,15 +1484,13 @@ describe('.toContain(), .toContainEqual()', () => { }); }); - if (isBigIntDefined) { - [[[BigInt(1), BigInt(2), BigInt(3)], 3]].forEach(([list, v]) => { - it(`'${stringify(list)}' does not contain '${stringify(v)}'`, () => { - jestExpect(list).not.toContain(v); + [[[BigInt(1), BigInt(2), BigInt(3)], 3]].forEach(([list, v]) => { + it(`'${stringify(list)}' does not contain '${stringify(v)}'`, () => { + jestExpect(list).not.toContain(v); - expect(() => jestExpect(list).toContain(v)).toThrowError('toContain'); - }); + expect(() => jestExpect(list).toContain(v)).toThrowError('toContain'); }); - } + }); test('error cases', () => { expect(() => jestExpect(null).toContain(1)).toThrowErrorMatchingSnapshot(); @@ -1538,11 +1504,9 @@ describe('.toContain(), .toContainEqual()', () => { expect(() => jestExpect('false').toContain(false), ).toThrowErrorMatchingSnapshot(); - if (isBigIntDefined) { - expect(() => jestExpect('1').toContain(BigInt(1))).toThrowError( - 'toContain', - ); - } + expect(() => jestExpect('1').toContain(BigInt(1))).toThrowError( + 'toContain', + ); }); [ diff --git a/packages/expect/src/asymmetricMatchers.ts b/packages/expect/src/asymmetricMatchers.ts index b52c62951d61..02b19c363956 100644 --- a/packages/expect/src/asymmetricMatchers.ts +++ b/packages/expect/src/asymmetricMatchers.ts @@ -73,7 +73,6 @@ class Any extends AsymmetricMatcher { return typeof other == 'boolean' || other instanceof Boolean; } - /* global BigInt */ if (this.sample == BigInt) { return typeof other == 'bigint' || other instanceof BigInt; } diff --git a/packages/jest-get-type/src/__tests__/getType.test.ts b/packages/jest-get-type/src/__tests__/getType.test.ts index 782f967c737e..9a38e889c790 100644 --- a/packages/jest-get-type/src/__tests__/getType.test.ts +++ b/packages/jest-get-type/src/__tests__/getType.test.ts @@ -22,8 +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')); - /* global BigInt */ - if (typeof BigInt === 'function') { - test('bigint', () => expect(getType(BigInt(1))).toBe('bigint')); - } + test('bigint', () => expect(getType(BigInt(1))).toBe('bigint')); }); diff --git a/packages/jest-get-type/src/__tests__/isPrimitive.test.ts b/packages/jest-get-type/src/__tests__/isPrimitive.test.ts index 02b1b3747f23..7d599a7ba4a9 100644 --- a/packages/jest-get-type/src/__tests__/isPrimitive.test.ts +++ b/packages/jest-get-type/src/__tests__/isPrimitive.test.ts @@ -7,7 +7,6 @@ */ import {isPrimitive} from '..'; -/* global BigInt */ describe('.isPrimitive()', () => { test.each([ @@ -20,7 +19,7 @@ describe('.isPrimitive()', () => { 0, NaN, Infinity, - typeof BigInt === 'function' ? BigInt(1) : 1, + BigInt(1), ])('returns true when given primitive value of: %s', primitive => { expect(isPrimitive(primitive)).toBe(true); }); diff --git a/packages/jest-matcher-utils/src/__tests__/index.test.ts b/packages/jest-matcher-utils/src/__tests__/index.test.ts index 5868096f1e83..668307405512 100644 --- a/packages/jest-matcher-utils/src/__tests__/index.test.ts +++ b/packages/jest-matcher-utils/src/__tests__/index.test.ts @@ -20,8 +20,6 @@ import { stringify, } from '../'; -const isBigIntDefined = typeof BigInt === 'function'; - expect.addSnapshotSerializer(alignedAnsiStyleSerializer); describe('stringify()', () => { @@ -39,8 +37,8 @@ describe('stringify()', () => { [Infinity, 'Infinity'], [-Infinity, '-Infinity'], [/ab\.c/gi, '/ab\\.c/gi'], - isBigIntDefined ? [BigInt(1), '1n'] : [12, '12'], - isBigIntDefined ? [BigInt(0), '0n'] : [123, '123'], + [BigInt(1), '1n'], + [BigInt(0), '0n'], ].forEach(([v, s]) => { test(stringify(v), () => { expect(stringify(v)).toBe(s); @@ -108,11 +106,9 @@ describe('ensureNumbers()', () => { expect(() => { ensureNumbers(1, 2, matcherName); }).not.toThrow(); - if (isBigIntDefined) { - expect(() => { - ensureNumbers(BigInt(1), BigInt(2), matcherName); - }).not.toThrow(); - } + expect(() => { + ensureNumbers(BigInt(1), BigInt(2), matcherName); + }).not.toThrow(); }); test('throws error when expected is not a number (backward compatibility)', () => { @@ -226,7 +222,7 @@ describe('diff', () => { ['a', 1], ['a', true], [1, true], - [isBigIntDefined ? BigInt(1) : 1, true], + [BigInt(1), true], ].forEach(([actual, expected]) => expect(diff(actual, expected)).toBe('diff output'), ); @@ -240,11 +236,9 @@ describe('diff', () => { expect(diff(1, 2)).toBe(null); }); - if (isBigIntDefined) { - test('two bigints', () => { - expect(diff(BigInt(1), BigInt(2))).toBe(null); - }); - } + test('two bigints', () => { + expect(diff(BigInt(1), BigInt(2))).toBe(null); + }); }); describe('pluralize()', () => { diff --git a/packages/pretty-format/src/__tests__/prettyFormat.test.ts b/packages/pretty-format/src/__tests__/prettyFormat.test.ts index 6b048c37cb28..fde20e6ac839 100644 --- a/packages/pretty-format/src/__tests__/prettyFormat.test.ts +++ b/packages/pretty-format/src/__tests__/prettyFormat.test.ts @@ -252,28 +252,25 @@ describe('prettyFormat()', () => { expect(prettyFormat(val)).toEqual('-0'); }); - /* global BigInt */ - if (typeof BigInt === 'function') { - it('prints a positive bigint', () => { - const val = BigInt(123); - expect(prettyFormat(val)).toEqual('123n'); - }); + it('prints a positive bigint', () => { + const val = BigInt(123); + expect(prettyFormat(val)).toEqual('123n'); + }); - it('prints a negative bigint', () => { - const val = BigInt(-123); - expect(prettyFormat(val)).toEqual('-123n'); - }); + it('prints a negative bigint', () => { + const val = BigInt(-123); + expect(prettyFormat(val)).toEqual('-123n'); + }); - it('prints zero bigint', () => { - const val = BigInt(0); - expect(prettyFormat(val)).toEqual('0n'); - }); + it('prints zero bigint', () => { + const val = BigInt(0); + expect(prettyFormat(val)).toEqual('0n'); + }); - it('prints negative zero bigint', () => { - const val = BigInt(-0); - expect(prettyFormat(val)).toEqual('0n'); - }); - } + it('prints negative zero bigint', () => { + const val = BigInt(-0); + expect(prettyFormat(val)).toEqual('0n'); + }); it('prints a date', () => { const val = new Date(10e11);