mirror of
https://github.com/hanzoai/jest.git
synced 2026-09-24 16:59:57 +00:00
chore: correctly use new for JS builtins (#14800)
This commit is contained in:
@@ -672,7 +672,6 @@ module.exports = {
|
||||
'unicorn/consistent-function-scoping': 'off',
|
||||
'unicorn/error-message': 'off',
|
||||
'unicorn/escape-case': 'off',
|
||||
'unicorn/new-for-builtins': 'off',
|
||||
'unicorn/no-array-method-this-argument': 'off',
|
||||
'unicorn/no-array-push-push': 'off',
|
||||
'unicorn/no-await-expression-member': 'off',
|
||||
|
||||
@@ -31,7 +31,7 @@ exports[`works with custom matchers 1`] = `
|
||||
qux
|
||||
|
||||
44 | const baz = () => {
|
||||
45 | // eslint-disable-next-line unicorn/throw-new-error
|
||||
45 | // eslint-disable-next-line unicorn/throw-new-error,unicorn/new-for-builtins
|
||||
> 46 | throw Error('qux');
|
||||
| ^
|
||||
47 | };
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('Custom matcher', () => {
|
||||
const foo = () => bar();
|
||||
const bar = () => baz();
|
||||
const baz = () => {
|
||||
// eslint-disable-next-line unicorn/throw-new-error
|
||||
// eslint-disable-next-line unicorn/throw-new-error,unicorn/new-for-builtins
|
||||
throw Error('qux');
|
||||
};
|
||||
|
||||
|
||||
@@ -472,7 +472,7 @@ export const pathAsArray = (propertyPath: string): Array<any> => {
|
||||
}
|
||||
|
||||
// will match everything that's not a dot or a bracket, and "" for consecutive dots.
|
||||
const pattern = RegExp('[^.[\\]]+|(?=(?:\\.)(?:\\.|$))', 'g');
|
||||
const pattern = new RegExp('[^.[\\]]+|(?=(?:\\.)(?:\\.|$))', 'g');
|
||||
|
||||
// Because the regex won't match a dot in the beginning of the path, if present.
|
||||
if (propertyPath[0] === '.') {
|
||||
|
||||
@@ -43,16 +43,15 @@ test('Any.asymmetricMatch()', () => {
|
||||
|
||||
test('Any.asymmetricMatch() on primitive wrapper classes', () => {
|
||||
for (const test of [
|
||||
// eslint-disable-next-line no-new-wrappers
|
||||
/* eslint-disable no-new-wrappers, unicorn/new-for-builtins */
|
||||
any(String).asymmetricMatch(new String('jest')),
|
||||
// eslint-disable-next-line no-new-wrappers
|
||||
any(Number).asymmetricMatch(new Number(1)),
|
||||
// eslint-disable-next-line no-new-func
|
||||
any(Function).asymmetricMatch(new Function('() => {}')),
|
||||
// eslint-disable-next-line no-new-wrappers
|
||||
any(Boolean).asymmetricMatch(new Boolean(true)),
|
||||
any(BigInt).asymmetricMatch(Object(1n)),
|
||||
any(Symbol).asymmetricMatch(Object(Symbol())),
|
||||
/* eslint-enable */
|
||||
]) {
|
||||
jestExpect(test).toBe(true);
|
||||
}
|
||||
|
||||
@@ -486,7 +486,7 @@ describe('.toStrictEqual()', () => {
|
||||
});
|
||||
|
||||
describe('.toEqual()', () => {
|
||||
/* eslint-disable no-new-wrappers */
|
||||
/* eslint-disable no-new-wrappers, unicorn/new-for-builtins */
|
||||
for (const [a, b] of [
|
||||
[true, false],
|
||||
[1, 2],
|
||||
|
||||
@@ -12,9 +12,7 @@ describe('rngBuilder', () => {
|
||||
// Some people will be using seeds relying on a particular order
|
||||
test.each([1, 2, 4, 8, 16])('creates a randomizer given seed %s', seed => {
|
||||
const rng = rngBuilder(seed);
|
||||
const results = Array(10)
|
||||
.fill(0)
|
||||
.map(() => rng.next(0, 10));
|
||||
const results = new Array(10).fill(0).map(() => rng.next(0, 10));
|
||||
expect(results).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -145,7 +145,7 @@ const buildContextsAndHasteMaps = async (
|
||||
globalConfig: Config.GlobalConfig,
|
||||
outputStream: WriteStream,
|
||||
) => {
|
||||
const hasteMapInstances = Array(configs.length);
|
||||
const hasteMapInstances = new Array(configs.length);
|
||||
const contexts = await Promise.all(
|
||||
configs.map(async (config, index) => {
|
||||
createDirectory(config.cacheDirectory);
|
||||
|
||||
@@ -101,7 +101,7 @@ describe('stringify()', () => {
|
||||
test('reduces maxWidth if stringifying very large arrays', () => {
|
||||
const big: any = [];
|
||||
const small: any = [];
|
||||
const testString = Array(1000).join('x');
|
||||
const testString = new Array(1000).join('x');
|
||||
|
||||
for (let i = 0; i < 100; i += 1) {
|
||||
big[i] = testString;
|
||||
|
||||
@@ -577,7 +577,7 @@ describe('prettyFormat()', () => {
|
||||
|
||||
describe('maxWidth option', () => {
|
||||
it('applies to arrays', () => {
|
||||
const val = Array(1_000_000).fill('x');
|
||||
const val = new Array(1_000_000).fill('x');
|
||||
expect(prettyFormat(val, {maxWidth: 5})).toEqual(
|
||||
[
|
||||
'Array [',
|
||||
|
||||
Reference in New Issue
Block a user