mirror of https://github.com/facebook/jest.git
chore: access Number globals via `Number` (#14807)
This commit is contained in:
parent
69fd995fea
commit
306a70aef8
|
@ -234,6 +234,7 @@ module.exports = {
|
|||
'no-undef': 'off',
|
||||
'no-unused-vars': 'off',
|
||||
'sort-keys': 'off',
|
||||
'unicorn/prefer-number-properties': 'off',
|
||||
'unicorn/no-static-only-class': 'off',
|
||||
},
|
||||
},
|
||||
|
@ -452,6 +453,12 @@ module.exports = {
|
|||
'unicorn/no-empty-file': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: 'packages/expect/src/__tests__/*.test.js',
|
||||
rules: {
|
||||
'unicorn/prefer-number-properties': 'off',
|
||||
},
|
||||
},
|
||||
],
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
|
@ -707,9 +714,6 @@ module.exports = {
|
|||
'unicorn/no-typeof-undefined': 'off',
|
||||
'unicorn/no-useless-undefined': 'off',
|
||||
'unicorn/prefer-logical-operator-over-ternary': 'off',
|
||||
'unicorn/prefer-math-trunc': 'off',
|
||||
'unicorn/prefer-native-coercion-functions': 'off',
|
||||
'unicorn/prefer-number-properties': 'off',
|
||||
'unicorn/prefer-object-from-entries': 'off',
|
||||
'unicorn/prefer-prototype-methods': 'off',
|
||||
'unicorn/prefer-spread': 'off',
|
||||
|
|
|
@ -772,7 +772,7 @@ exports[`works with node assert 1`] = `
|
|||
|
||||
48 |
|
||||
49 | test('assert.strictEqual', () => {
|
||||
> 50 | assert.strictEqual(1, NaN);
|
||||
> 50 | assert.strictEqual(1, Number.NaN);
|
||||
| ^
|
||||
51 | });
|
||||
52 |
|
||||
|
|
|
@ -19,9 +19,9 @@ describe('array', () => {
|
|||
[noop, noop],
|
||||
[[], []],
|
||||
[[{foo: {bar: 'baz'}}], [{foo: {bar: 'baz'}}]],
|
||||
[Infinity, Infinity],
|
||||
[-Infinity, -Infinity],
|
||||
[NaN, NaN],
|
||||
[Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY],
|
||||
[Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY],
|
||||
[Number.NaN, Number.NaN],
|
||||
])('%p == %p', (left, right) => {
|
||||
expect(left).toEqual(right);
|
||||
});
|
||||
|
@ -29,20 +29,20 @@ describe('array', () => {
|
|||
|
||||
describe('template', () => {
|
||||
it.each`
|
||||
left | right
|
||||
${'hello'} | ${'hello'}
|
||||
${1} | ${1}
|
||||
${null} | ${null}
|
||||
${undefined} | ${undefined}
|
||||
${1.2} | ${1.2}
|
||||
${{foo: 'bar'}} | ${{foo: 'bar'}}
|
||||
${{foo: {bar: 'baz'}}} | ${{foo: {bar: 'baz'}}}
|
||||
${noop} | ${noop}
|
||||
${[]} | ${[]}
|
||||
${[{foo: {bar: 'baz'}}]} | ${[{foo: {bar: 'baz'}}]}
|
||||
${Infinity} | ${Infinity}
|
||||
${-Infinity} | ${-Infinity}
|
||||
${NaN} | ${NaN}
|
||||
left | right
|
||||
${'hello'} | ${'hello'}
|
||||
${1} | ${1}
|
||||
${null} | ${null}
|
||||
${undefined} | ${undefined}
|
||||
${1.2} | ${1.2}
|
||||
${{foo: 'bar'}} | ${{foo: 'bar'}}
|
||||
${{foo: {bar: 'baz'}}} | ${{foo: {bar: 'baz'}}}
|
||||
${noop} | ${noop}
|
||||
${[]} | ${[]}
|
||||
${[{foo: {bar: 'baz'}}]} | ${[{foo: {bar: 'baz'}}]}
|
||||
${Number.POSITIVE_INFINITY} | ${Number.POSITIVE_INFINITY}
|
||||
${Number.NEGATIVE_INFINITY} | ${Number.NEGATIVE_INFINITY}
|
||||
${Number.NaN} | ${Number.NaN}
|
||||
`('$left == $right', ({left, right}) => {
|
||||
expect(left).toEqual(right);
|
||||
});
|
||||
|
|
|
@ -47,7 +47,7 @@ test('assert.notDeepEqual', () => {
|
|||
});
|
||||
|
||||
test('assert.strictEqual', () => {
|
||||
assert.strictEqual(1, NaN);
|
||||
assert.strictEqual(1, Number.NaN);
|
||||
});
|
||||
|
||||
test('assert.notStrictEqual', () => {
|
||||
|
|
|
@ -13,8 +13,8 @@ describe('returning values', () => {
|
|||
'string',
|
||||
0.1,
|
||||
null,
|
||||
NaN,
|
||||
Infinity,
|
||||
Number.NaN,
|
||||
Number.POSITIVE_INFINITY,
|
||||
true,
|
||||
false,
|
||||
[1],
|
||||
|
|
|
@ -18,7 +18,7 @@ beforeAll(() => {
|
|||
jest.retryTimes(3);
|
||||
|
||||
it('retries', () => {
|
||||
const tries = parseInt(fs.readFileSync(countPath, 'utf8'), 10);
|
||||
const tries = Number.parseInt(fs.readFileSync(countPath, 'utf8'), 10);
|
||||
fs.writeFileSync(countPath, `${tries + 1}`, 'utf8');
|
||||
expect(tries).toBe(3);
|
||||
});
|
||||
|
|
|
@ -9,7 +9,7 @@ const users = {
|
|||
|
||||
export default function request(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const userID = parseInt(url.slice('/users/'.length), 10);
|
||||
const userID = Number.parseInt(url.slice('/users/'.length), 10);
|
||||
process.nextTick(() =>
|
||||
users[userID]
|
||||
? resolve(users[userID])
|
||||
|
|
|
@ -21,12 +21,12 @@ describe('invalid arg', () => {
|
|||
});
|
||||
test('Infinity is not a safe integer', () => {
|
||||
expect(() => {
|
||||
diff(Infinity, 0, isCommon, foundSubsequence);
|
||||
diff(Number.POSITIVE_INFINITY, 0, isCommon, foundSubsequence);
|
||||
}).toThrow(/aLength/);
|
||||
});
|
||||
test('Not a Number is not a safe integer', () => {
|
||||
expect(() => {
|
||||
diff(NaN, 0, isCommon, foundSubsequence);
|
||||
diff(Number.NaN, 0, isCommon, foundSubsequence);
|
||||
}).toThrow(/aLength/);
|
||||
});
|
||||
|
||||
|
@ -109,7 +109,7 @@ describe('input callback encapsulates comparison', () => {
|
|||
|
||||
describe('Not a Number', () => {
|
||||
// input callback encapsulates identical sequences
|
||||
const a = [NaN];
|
||||
const a = [Number.NaN];
|
||||
|
||||
test('is common according to Object.is method', () => {
|
||||
expect(countCommonObjectIs(a, a)).toBe(1);
|
||||
|
|
|
@ -415,8 +415,8 @@ describe('closeTo', () => {
|
|||
[1.23, 1.226],
|
||||
[1.23, 1.225],
|
||||
[1.23, 1.234],
|
||||
[Infinity, Infinity],
|
||||
[-Infinity, -Infinity],
|
||||
[Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY],
|
||||
[Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY],
|
||||
]) {
|
||||
test(`${expected} closeTo ${received} return true`, () => {
|
||||
jestExpect(closeTo(expected).asymmetricMatch(received)).toBe(true);
|
||||
|
@ -430,9 +430,9 @@ describe('closeTo', () => {
|
|||
[0, 0.01],
|
||||
[1, 1.23],
|
||||
[1.23, 1.224_999_9],
|
||||
[Infinity, -Infinity],
|
||||
[Infinity, 1.23],
|
||||
[-Infinity, -1.23],
|
||||
[Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY],
|
||||
[Number.POSITIVE_INFINITY, 1.23],
|
||||
[Number.NEGATIVE_INFINITY, -1.23],
|
||||
]) {
|
||||
test(`${expected} closeTo ${received} return false`, () => {
|
||||
jestExpect(closeTo(expected).asymmetricMatch(received)).toBe(false);
|
||||
|
|
|
@ -649,7 +649,7 @@ describe.each([
|
|||
fn('foo1', 'bar');
|
||||
|
||||
expect(() => {
|
||||
jestExpect(fn).not[calledWith](Infinity, 'foo1', 'bar');
|
||||
jestExpect(fn).not[calledWith](Number.POSITIVE_INFINITY, 'foo1', 'bar');
|
||||
}).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -333,9 +333,15 @@ class CloseTo extends AsymmetricMatcher<number> {
|
|||
return false;
|
||||
}
|
||||
let result = false;
|
||||
if (other === Infinity && this.sample === Infinity) {
|
||||
if (
|
||||
other === Number.POSITIVE_INFINITY &&
|
||||
this.sample === Number.POSITIVE_INFINITY
|
||||
) {
|
||||
result = true; // Infinity - Infinity is NaN
|
||||
} else if (other === -Infinity && this.sample === -Infinity) {
|
||||
} else if (
|
||||
other === Number.NEGATIVE_INFINITY &&
|
||||
this.sample === Number.NEGATIVE_INFINITY
|
||||
) {
|
||||
result = true; // -Infinity - -Infinity is NaN
|
||||
} else {
|
||||
result =
|
||||
|
|
|
@ -176,9 +176,15 @@ const matchers: MatchersObject = {
|
|||
let expectedDiff = 0;
|
||||
let receivedDiff = 0;
|
||||
|
||||
if (received === Infinity && expected === Infinity) {
|
||||
if (
|
||||
received === Number.POSITIVE_INFINITY &&
|
||||
expected === Number.POSITIVE_INFINITY
|
||||
) {
|
||||
pass = true; // Infinity - Infinity is NaN
|
||||
} else if (received === -Infinity && expected === -Infinity) {
|
||||
} else if (
|
||||
received === Number.NEGATIVE_INFINITY &&
|
||||
expected === Number.NEGATIVE_INFINITY
|
||||
) {
|
||||
pass = true; // -Infinity - -Infinity is NaN
|
||||
} else {
|
||||
expectedDiff = Math.pow(10, -precision) / 2;
|
||||
|
|
|
@ -70,11 +70,14 @@ const _runTestsForDescribeBlock = async (
|
|||
// Tests that fail and are retried we run after other tests
|
||||
const retryTimes =
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
parseInt((global as Global.Global)[RETRY_TIMES] as string, 10) || 0;
|
||||
Number.parseInt((global as Global.Global)[RETRY_TIMES] as string, 10) || 0;
|
||||
|
||||
const waitBeforeRetry =
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
parseInt((global as Global.Global)[WAIT_BEFORE_RETRY] as string, 10) || 0;
|
||||
Number.parseInt(
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
(global as Global.Global)[WAIT_BEFORE_RETRY] as string,
|
||||
10,
|
||||
) || 0;
|
||||
const deferredRetryTests = [];
|
||||
|
||||
if (rng) {
|
||||
|
|
|
@ -74,7 +74,7 @@ it('picks an id based on the rootDir', async () => {
|
|||
const rootDir = '/root/path/foo';
|
||||
const expected = createHash('sha1')
|
||||
.update('/root/path/foo')
|
||||
.update(String(Infinity))
|
||||
.update(String(Number.POSITIVE_INFINITY))
|
||||
.digest('hex')
|
||||
.slice(0, 32);
|
||||
const {options} = await normalize(
|
||||
|
|
|
@ -42,7 +42,7 @@ export default function getMaxWorkers(
|
|||
}
|
||||
|
||||
const parseWorkers = (maxWorkers: string | number): number => {
|
||||
const parsed = parseInt(maxWorkers.toString(), 10);
|
||||
const parsed = Number.parseInt(maxWorkers.toString(), 10);
|
||||
|
||||
if (
|
||||
typeof maxWorkers === 'string' &&
|
||||
|
|
|
@ -40,7 +40,7 @@ export async function readConfig(
|
|||
// read individual configs for every project.
|
||||
skipArgvConfigOption?: boolean,
|
||||
parentConfigDirname?: string | null,
|
||||
projectIndex = Infinity,
|
||||
projectIndex = Number.POSITIVE_INFINITY,
|
||||
skipMultipleConfigError = false,
|
||||
): Promise<ReadConfig> {
|
||||
const {config: initialOptions, configPath} = await readInitialOptions(
|
||||
|
|
|
@ -487,7 +487,7 @@ export default async function normalize(
|
|||
initialOptions: Config.InitialOptions,
|
||||
argv: Config.Argv,
|
||||
configPath?: string | null,
|
||||
projectIndex = Infinity,
|
||||
projectIndex = Number.POSITIVE_INFINITY,
|
||||
isProjectOptions?: boolean,
|
||||
): Promise<{
|
||||
hasDeprecationWarnings: boolean;
|
||||
|
@ -1009,7 +1009,7 @@ export default async function normalize(
|
|||
newOptions.testPathPatterns = testPathPatterns.patterns;
|
||||
newOptions.json = !!argv.json;
|
||||
|
||||
newOptions.testFailureExitCode = parseInt(
|
||||
newOptions.testFailureExitCode = Number.parseInt(
|
||||
newOptions.testFailureExitCode as unknown as string,
|
||||
10,
|
||||
);
|
||||
|
@ -1086,7 +1086,7 @@ export default async function normalize(
|
|||
? 'all'
|
||||
: 'new';
|
||||
|
||||
newOptions.maxConcurrency = parseInt(
|
||||
newOptions.maxConcurrency = Number.parseInt(
|
||||
newOptions.maxConcurrency as unknown as string,
|
||||
10,
|
||||
);
|
||||
|
|
|
@ -13,7 +13,7 @@ export const parseShardPair = (pair: string): ShardPair => {
|
|||
const shardPair = pair
|
||||
.split('/')
|
||||
.filter(d => /^\d+$/.test(d))
|
||||
.map(d => parseInt(d, 10))
|
||||
.map(d => Number.parseInt(d, 10))
|
||||
.filter(shard => !Number.isNaN(shard));
|
||||
|
||||
const [shardIndex, shardCount] = shardPair;
|
||||
|
|
|
@ -30,7 +30,7 @@ function stringToBytes(
|
|||
}
|
||||
|
||||
if (typeof input === 'string') {
|
||||
if (isNaN(Number.parseFloat(input.slice(-1)))) {
|
||||
if (Number.isNaN(Number.parseFloat(input.slice(-1)))) {
|
||||
// eslint-disable-next-line prefer-const
|
||||
let [, numericString, trailingChars] =
|
||||
input.match(/(.*?)([^\d.-]+)$/i) || [];
|
||||
|
|
|
@ -33,7 +33,7 @@ export default function getNoTestFoundVerbose(
|
|||
}
|
||||
return null;
|
||||
})
|
||||
.filter(line => line)
|
||||
.filter(Boolean)
|
||||
.join('\n');
|
||||
|
||||
return testRun.matches.total
|
||||
|
|
|
@ -78,8 +78,10 @@ describe('no visual difference', () => {
|
|||
[1, 2],
|
||||
],
|
||||
[11, 11],
|
||||
/* eslint-disable unicorn/prefer-number-properties */
|
||||
[NaN, NaN],
|
||||
[Number.NaN, NaN],
|
||||
/* eslint-enable */
|
||||
[() => {}, () => {}],
|
||||
[null, null],
|
||||
[undefined, undefined],
|
||||
|
|
|
@ -126,8 +126,8 @@ describe('jest-each', () => {
|
|||
{foo: 'bar'},
|
||||
() => {},
|
||||
[],
|
||||
Infinity,
|
||||
NaN,
|
||||
Number.POSITIVE_INFINITY,
|
||||
Number.NaN,
|
||||
],
|
||||
[
|
||||
'world',
|
||||
|
@ -138,8 +138,8 @@ describe('jest-each', () => {
|
|||
{baz: 'qux'},
|
||||
() => {},
|
||||
[],
|
||||
Infinity,
|
||||
NaN,
|
||||
Number.POSITIVE_INFINITY,
|
||||
Number.NaN,
|
||||
],
|
||||
]);
|
||||
const testFunction = get(eachObject, keyPath);
|
||||
|
@ -304,8 +304,8 @@ describe('jest-each', () => {
|
|||
f: {key: 'foo'},
|
||||
g: () => {},
|
||||
h: [],
|
||||
i: Infinity,
|
||||
j: NaN,
|
||||
i: Number.POSITIVE_INFINITY,
|
||||
j: Number.NaN,
|
||||
},
|
||||
{
|
||||
a: 'world',
|
||||
|
@ -316,8 +316,8 @@ describe('jest-each', () => {
|
|||
f: {key: 'bar'},
|
||||
g: () => {},
|
||||
h: [],
|
||||
i: Infinity,
|
||||
j: NaN,
|
||||
i: Number.POSITIVE_INFINITY,
|
||||
j: Number.NaN,
|
||||
},
|
||||
]);
|
||||
const testFunction = get(eachObject, keyPath);
|
||||
|
|
|
@ -485,14 +485,14 @@ describe('FakeTimers', () => {
|
|||
const mockAnimationFrame = jest.fn(() => runOrder.push('animationFrame'));
|
||||
|
||||
global.setTimeout(mock1, 100);
|
||||
global.setTimeout(mock2, NaN);
|
||||
global.setTimeout(mock2, Number.NaN);
|
||||
global.setTimeout(mock3, 0);
|
||||
const intervalHandler = global.setInterval(() => {
|
||||
mock4();
|
||||
global.clearInterval(intervalHandler);
|
||||
}, 200);
|
||||
global.setTimeout(mock5, Infinity);
|
||||
global.setTimeout(mock6, -Infinity);
|
||||
global.setTimeout(mock5, Number.POSITIVE_INFINITY);
|
||||
global.setTimeout(mock6, Number.NEGATIVE_INFINITY);
|
||||
global.requestAnimationFrame(mockAnimationFrame);
|
||||
|
||||
timers.runAllTimers();
|
||||
|
|
|
@ -251,14 +251,14 @@ describe('FakeTimers', () => {
|
|||
const mock6 = jest.fn(() => runOrder.push('mock6'));
|
||||
|
||||
global.setTimeout(mock1, 100);
|
||||
global.setTimeout(mock2, NaN);
|
||||
global.setTimeout(mock2, Number.NaN);
|
||||
global.setTimeout(mock3, 0);
|
||||
const intervalHandler = global.setInterval(() => {
|
||||
mock4();
|
||||
global.clearInterval(intervalHandler);
|
||||
}, 200);
|
||||
global.setTimeout(mock5, Infinity);
|
||||
global.setTimeout(mock6, -Infinity);
|
||||
global.setTimeout(mock5, Number.POSITIVE_INFINITY);
|
||||
global.setTimeout(mock6, Number.NEGATIVE_INFINITY);
|
||||
|
||||
timers.runAllTimers();
|
||||
expect(runOrder).toEqual([
|
||||
|
|
|
@ -560,7 +560,7 @@ export default class FakeTimers<TimerRef = unknown> {
|
|||
return null;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-bitwise
|
||||
// eslint-disable-next-line no-bitwise,unicorn/prefer-math-trunc
|
||||
delay = Number(delay) | 0;
|
||||
|
||||
const uuid = this._uuidCounter++;
|
||||
|
|
|
@ -17,8 +17,8 @@ describe('.isPrimitive()', () => {
|
|||
true,
|
||||
Symbol.for('a'),
|
||||
0,
|
||||
NaN,
|
||||
Infinity,
|
||||
Number.NaN,
|
||||
Number.POSITIVE_INFINITY,
|
||||
BigInt(1),
|
||||
])('returns true when given primitive value of: %s', primitive => {
|
||||
expect(isPrimitive(primitive)).toBe(true);
|
||||
|
|
|
@ -28,7 +28,7 @@ it('complains if the value is a primitive', () => {
|
|||
expect(() => new LeakDetector('foo')).toThrowErrorMatchingSnapshot();
|
||||
expect(() => new LeakDetector(Symbol())).toThrowErrorMatchingSnapshot();
|
||||
expect(() => new LeakDetector(Symbol('foo'))).toThrowErrorMatchingSnapshot();
|
||||
expect(() => new LeakDetector(NaN)).toThrowErrorMatchingSnapshot();
|
||||
expect(() => new LeakDetector(Number.NaN)).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
it('does not show the GC if hidden', async () => {
|
||||
|
|
|
@ -15,7 +15,7 @@ test('returns the same value for primitive or function values', () => {
|
|||
expect(deepCyclicCopyReplaceable(null)).toBeNull();
|
||||
expect(deepCyclicCopyReplaceable(true)).toBe(true);
|
||||
expect(deepCyclicCopyReplaceable(42)).toBe(42);
|
||||
expect(Number.isNaN(deepCyclicCopyReplaceable(NaN))).toBe(true);
|
||||
expect(Number.isNaN(deepCyclicCopyReplaceable(Number.NaN))).toBe(true);
|
||||
expect(deepCyclicCopyReplaceable('foo')).toBe('foo');
|
||||
expect(deepCyclicCopyReplaceable(fn)).toBe(fn);
|
||||
});
|
||||
|
|
|
@ -33,9 +33,14 @@ describe('stringify()', () => {
|
|||
[undefined, 'undefined'],
|
||||
['abc', '"abc"'],
|
||||
[Symbol.for('abc'), 'Symbol(abc)'],
|
||||
/* eslint-disable unicorn/prefer-number-properties */
|
||||
[NaN, 'NaN'],
|
||||
[Infinity, 'Infinity'],
|
||||
[-Infinity, '-Infinity'],
|
||||
/* eslint-enable */
|
||||
[Number.NaN, 'NaN'],
|
||||
[Number.POSITIVE_INFINITY, 'Infinity'],
|
||||
[Number.NEGATIVE_INFINITY, '-Infinity'],
|
||||
[/ab\.c/gi, '/ab\\.c/gi'],
|
||||
[BigInt(1), '1n'],
|
||||
[BigInt(0), '0n'],
|
||||
|
|
|
@ -49,7 +49,9 @@ describe('moduleMocker', () => {
|
|||
expect(moduleMocker.getMetadata('banana').value).toBe('banana');
|
||||
expect(moduleMocker.getMetadata(27).value).toBe(27);
|
||||
expect(moduleMocker.getMetadata(false).value).toBe(false);
|
||||
expect(moduleMocker.getMetadata(Infinity).value).toEqual(Infinity);
|
||||
expect(moduleMocker.getMetadata(Number.POSITIVE_INFINITY).value).toEqual(
|
||||
Number.POSITIVE_INFINITY,
|
||||
);
|
||||
});
|
||||
|
||||
it('does not retrieve metadata for arrays', () => {
|
||||
|
@ -1326,16 +1328,16 @@ describe('moduleMocker', () => {
|
|||
|
||||
describe('should throw', () => {
|
||||
it.each`
|
||||
value | type
|
||||
${'foo'} | ${'string'}
|
||||
${1} | ${'number'}
|
||||
${NaN} | ${'number'}
|
||||
${1n} | ${'bigint'}
|
||||
${Symbol()} | ${'symbol'}
|
||||
${true} | ${'boolean'}
|
||||
${false} | ${'boolean'}
|
||||
${undefined} | ${'undefined'}
|
||||
${null} | ${'null'}
|
||||
value | type
|
||||
${'foo'} | ${'string'}
|
||||
${1} | ${'number'}
|
||||
${Number.NaN} | ${'number'}
|
||||
${1n} | ${'bigint'}
|
||||
${Symbol()} | ${'symbol'}
|
||||
${true} | ${'boolean'}
|
||||
${false} | ${'boolean'}
|
||||
${undefined} | ${'undefined'}
|
||||
${null} | ${'null'}
|
||||
`(
|
||||
'when primitive value $value is provided instead of an object',
|
||||
({value, type}) => {
|
||||
|
@ -2208,16 +2210,16 @@ describe('moduleMocker', () => {
|
|||
|
||||
describe('should throw', () => {
|
||||
it.each`
|
||||
value | type
|
||||
${'foo'} | ${'string'}
|
||||
${1} | ${'number'}
|
||||
${NaN} | ${'number'}
|
||||
${1n} | ${'bigint'}
|
||||
${Symbol()} | ${'symbol'}
|
||||
${true} | ${'boolean'}
|
||||
${false} | ${'boolean'}
|
||||
${undefined} | ${'undefined'}
|
||||
${null} | ${'null'}
|
||||
value | type
|
||||
${'foo'} | ${'string'}
|
||||
${1} | ${'number'}
|
||||
${Number.NaN} | ${'number'}
|
||||
${1n} | ${'bigint'}
|
||||
${Symbol()} | ${'symbol'}
|
||||
${true} | ${'boolean'}
|
||||
${false} | ${'boolean'}
|
||||
${undefined} | ${'undefined'}
|
||||
${null} | ${'null'}
|
||||
`(
|
||||
'when primitive value $value is provided instead of an object',
|
||||
({value, type}) => {
|
||||
|
|
|
@ -21,7 +21,7 @@ function summarize(coverageMap: CoverageMap): CoverageMap {
|
|||
const lineCoverage = coverageMap.fileCoverageFor(file).getLineCoverage();
|
||||
|
||||
for (const lineNumber of Object.keys(lineCoverage)) {
|
||||
const number = parseInt(lineNumber, 10);
|
||||
const number = Number.parseInt(lineNumber, 10);
|
||||
// Line numbers start at one
|
||||
covered[number - 1] = lineCoverage[number] ? 'C' : 'U';
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ export default class CoverageReporter extends BaseReporter {
|
|||
}
|
||||
istanbulReports
|
||||
.create(reporter, {
|
||||
maxCols: process.stdout.columns || Infinity,
|
||||
maxCols: process.stdout.columns || Number.POSITIVE_INFINITY,
|
||||
...additionalOptions,
|
||||
})
|
||||
.execute(reportContext);
|
||||
|
|
|
@ -262,7 +262,7 @@ export default class GitHubActionsReporter extends BaseReporter {
|
|||
const branches: Array<Array<string>> = [];
|
||||
for (const element of suiteResult) {
|
||||
let duration = element.duration;
|
||||
if (!duration || isNaN(duration)) {
|
||||
if (!duration || Number.isNaN(duration)) {
|
||||
duration = 1;
|
||||
}
|
||||
if (this.arrayEqual(element.ancestorTitles, ancestors)) {
|
||||
|
|
|
@ -439,7 +439,7 @@ describe('onRunComplete', () => {
|
|||
.onRunComplete(new Set(), {}, mockAggResults)
|
||||
.then(() => {
|
||||
expect(istanbulReports.create).toHaveBeenCalledWith('json', {
|
||||
maxCols: process.stdout.columns || Infinity,
|
||||
maxCols: process.stdout.columns || Number.POSITIVE_INFINITY,
|
||||
});
|
||||
expect(istanbulReports.create).toHaveBeenCalledWith('lcov', {
|
||||
maxCols: 10,
|
||||
|
|
|
@ -439,7 +439,7 @@ export default class Resolver {
|
|||
? (moduleName: string) =>
|
||||
moduleName.replace(
|
||||
/\$(\d+)/g,
|
||||
(_, index) => matches[parseInt(index, 10)] || '',
|
||||
(_, index) => matches[Number.parseInt(index, 10)] || '',
|
||||
)
|
||||
: (moduleName: string) => moduleName;
|
||||
}
|
||||
|
|
|
@ -1164,7 +1164,7 @@ describe('printSnapshotAndReceived', () => {
|
|||
|
||||
test('number', () => {
|
||||
const expected = -0;
|
||||
const received = NaN;
|
||||
const received = Number.NaN;
|
||||
|
||||
expect(testWithStringify(expected, received, false)).toMatchSnapshot();
|
||||
});
|
||||
|
|
|
@ -15,7 +15,7 @@ it('returns the same value for primitive or function values', () => {
|
|||
expect(deepCyclicCopy(null)).toBeNull();
|
||||
expect(deepCyclicCopy(true)).toBe(true);
|
||||
expect(deepCyclicCopy(42)).toBe(42);
|
||||
expect(Number.isNaN(deepCyclicCopy(NaN))).toBe(true);
|
||||
expect(Number.isNaN(deepCyclicCopy(Number.NaN))).toBe(true);
|
||||
expect(deepCyclicCopy('foo')).toBe('foo');
|
||||
expect(deepCyclicCopy(fn)).toBe(fn);
|
||||
});
|
||||
|
|
|
@ -149,8 +149,8 @@ test('a function constructor', new Function());
|
|||
test('an anonymous function', () => {});
|
||||
function named() {}
|
||||
test('a named function', named);
|
||||
test('Infinity', Infinity);
|
||||
test('-Infinity', -Infinity);
|
||||
test('Infinity', Number.POSITIVE_INFINITY);
|
||||
test('-Infinity', Number.NEGATIVE_INFINITY);
|
||||
test('an empty map', new Map());
|
||||
const mapWithValues = new Map();
|
||||
const mapWithNonStringKeys = new Map();
|
||||
|
@ -159,7 +159,7 @@ mapWithValues.set('prop2', 'value2');
|
|||
mapWithNonStringKeys.set({prop: 'value'}, {prop: 'value'});
|
||||
test('a map with values', mapWithValues);
|
||||
test('a map with non-string keys', mapWithNonStringKeys);
|
||||
test('NaN', NaN);
|
||||
test('NaN', Number.NaN);
|
||||
test('null', null);
|
||||
test('a number', 123);
|
||||
test('a date', new Date(10e11));
|
||||
|
|
|
@ -149,7 +149,10 @@ test('closeTo(number)', () => {
|
|||
});
|
||||
|
||||
test('closeTo(Infinity)', () => {
|
||||
const result = prettyFormat(expect.closeTo(-Infinity), options);
|
||||
const result = prettyFormat(
|
||||
expect.closeTo(Number.NEGATIVE_INFINITY),
|
||||
options,
|
||||
);
|
||||
expect(result).toBe('NumberCloseTo -Infinity (2 digits)');
|
||||
});
|
||||
|
||||
|
|
|
@ -950,8 +950,8 @@ describe('Immutable.Seq lazy values', () => {
|
|||
const filterer = (item: string) => item.length > 0;
|
||||
|
||||
test('from Immutable.Range', () => {
|
||||
const val = Immutable.Range(1, Infinity);
|
||||
expect(val.size).toBe(Infinity);
|
||||
const val = Immutable.Range(1, Number.POSITIVE_INFINITY);
|
||||
expect(val.size).toBe(Number.POSITIVE_INFINITY);
|
||||
expect(val).toPrettyPrintTo(expected);
|
||||
});
|
||||
|
||||
|
|
|
@ -165,12 +165,12 @@ describe('prettyFormat()', () => {
|
|||
});
|
||||
|
||||
it('prints Infinity', () => {
|
||||
const val = Infinity;
|
||||
const val = Number.POSITIVE_INFINITY;
|
||||
expect(prettyFormat(val)).toBe('Infinity');
|
||||
});
|
||||
|
||||
it('prints -Infinity', () => {
|
||||
const val = -Infinity;
|
||||
const val = Number.NEGATIVE_INFINITY;
|
||||
expect(prettyFormat(val)).toBe('-Infinity');
|
||||
});
|
||||
|
||||
|
@ -228,7 +228,7 @@ describe('prettyFormat()', () => {
|
|||
});
|
||||
|
||||
it('prints NaN', () => {
|
||||
const val = NaN;
|
||||
const val = Number.NaN;
|
||||
expect(prettyFormat(val)).toBe('NaN');
|
||||
});
|
||||
|
||||
|
@ -283,7 +283,7 @@ describe('prettyFormat()', () => {
|
|||
});
|
||||
|
||||
it('prints an invalid date', () => {
|
||||
const val = new Date(Infinity);
|
||||
const val = new Date(Number.POSITIVE_INFINITY);
|
||||
expect(prettyFormat(val)).toBe('Date { NaN }');
|
||||
});
|
||||
|
||||
|
@ -914,7 +914,15 @@ describe('prettyFormat()', () => {
|
|||
const val = {
|
||||
boolean: [false, true],
|
||||
null: null,
|
||||
number: [0, -0, 123, -123, Infinity, -Infinity, NaN],
|
||||
number: [
|
||||
0,
|
||||
-0,
|
||||
123,
|
||||
-123,
|
||||
Number.POSITIVE_INFINITY,
|
||||
Number.NEGATIVE_INFINITY,
|
||||
Number.NaN,
|
||||
],
|
||||
string: ['', 'non-empty'],
|
||||
undefined,
|
||||
};
|
||||
|
|
|
@ -175,7 +175,7 @@ function printBasicValue(
|
|||
return printSymbol(val);
|
||||
}
|
||||
if (toStringed === '[object Date]') {
|
||||
return isNaN(+val) ? 'Date { NaN }' : toISOString.call(val);
|
||||
return Number.isNaN(+val) ? 'Date { NaN }' : toISOString.call(val);
|
||||
}
|
||||
if (toStringed === '[object Error]') {
|
||||
return printError(val);
|
||||
|
@ -410,8 +410,8 @@ export const DEFAULT_OPTIONS = toOptionsSubtype({
|
|||
escapeString: true,
|
||||
highlight: false,
|
||||
indent: 2,
|
||||
maxDepth: Infinity,
|
||||
maxWidth: Infinity,
|
||||
maxDepth: Number.POSITIVE_INFINITY,
|
||||
maxWidth: Number.POSITIVE_INFINITY,
|
||||
min: false,
|
||||
plugins: [],
|
||||
printBasicPrototype: true,
|
||||
|
|
|
@ -27,7 +27,7 @@ export function setupLandingAnimation() {
|
|||
function positionCards() {
|
||||
const handWidth = hand.offsetWidth;
|
||||
for (const card of cards) {
|
||||
const offset = parseInt(card.dataset.index, 10) - 2;
|
||||
const offset = Number.parseInt(card.dataset.index, 10) - 2;
|
||||
card.parentElement.style.transform = cardTransform(offset, handWidth);
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ export function setupLandingAnimation() {
|
|||
card = ev.target.parentElement;
|
||||
}
|
||||
if (card) {
|
||||
const index = parseInt(card.dataset.index, 10);
|
||||
const index = Number.parseInt(card.dataset.index, 10);
|
||||
runTest(card, index);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue