diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 867858b4fb96..fd71b67c8653 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -476,7 +476,7 @@ module.exports = { 'constructor-super': 'error', 'default-case': 'off', 'dot-notation': 'off', - eqeqeq: ['off', 'allow-null'], + eqeqeq: ['error', 'smart'], 'eslint-comments/disable-enable-pair': ['error', {allowWholeFile: true}], 'eslint-comments/no-unused-disable': 'error', 'func-names': 'off', diff --git a/docs/ExpectAPI.md b/docs/ExpectAPI.md index dd03a3e76bfc..336564856346 100644 --- a/docs/ExpectAPI.md +++ b/docs/ExpectAPI.md @@ -789,7 +789,7 @@ For example, let's say that `drinkFlavor` is coded like this: ```js function drinkFlavor(flavor) { - if (flavor == 'octopus') { + if (flavor === 'octopus') { throw new DisgustingFlavorError('yuck, octopus flavor'); } // Do some other stuff @@ -827,7 +827,7 @@ For example, let's say you have a `drinkFlavor` function that throws whenever th ```js function drinkFlavor(flavor) { - if (flavor == 'octopus') { + if (flavor === 'octopus') { throw new DisgustingFlavorError('yuck, octopus flavor'); } // Do some other stuff @@ -1505,7 +1505,7 @@ expect.extend({ expect.extend({ async toBeDivisibleByExternalValue(received) { const externalValue = await getExternalValueFromRemoteSource(); - const pass = received % externalValue == 0; + const pass = received % externalValue === 0; if (pass) { return { message: () => diff --git a/e2e/__tests__/jsonReporter.test.ts b/e2e/__tests__/jsonReporter.test.ts index 03b01a6fccf2..87bed8e2c518 100644 --- a/e2e/__tests__/jsonReporter.test.ts +++ b/e2e/__tests__/jsonReporter.test.ts @@ -46,28 +46,28 @@ describe('JSON Reporter', () => { expect(jsonResult.numPendingTests).toBe(1); const noAncestors = jsonResult.testResults[0].assertionResults.find( - item => item.title == 'no ancestors', + item => item.title === 'no ancestors', ); let expected = {ancestorTitles: [] as Array}; expect(noAncestors).toEqual(expect.objectContaining(expected)); expect(noAncestors).toHaveProperty('duration', expect.any(Number)); const addsNumbers = jsonResult.testResults[0].assertionResults.find( - item => item.title == 'adds numbers', + item => item.title === 'adds numbers', ); expected = {ancestorTitles: ['sum']}; expect(addsNumbers).toEqual(expect.objectContaining(expected)); expect(addsNumbers).toHaveProperty('duration', expect.any(Number)); const failsTheTest = jsonResult.testResults[0].assertionResults.find( - item => item.title == 'fails the test', + item => item.title === 'fails the test', ); expected = {ancestorTitles: ['sum', 'failing tests']}; expect(failsTheTest).toEqual(expect.objectContaining(expected)); expect(failsTheTest).toHaveProperty('duration', expect.any(Number)); const skipedTest = jsonResult.testResults[0].assertionResults.find( - item => item.title == 'skipped test', + item => item.title === 'skipped test', ); expect(skipedTest).toHaveProperty('duration', null); }); @@ -99,19 +99,19 @@ describe('JSON Reporter', () => { expect(jsonResult.numPendingTests).toBe(1); const noAncestors = jsonResult.testResults[0].assertionResults.find( - item => item.title == 'no ancestors', + item => item.title === 'no ancestors', ); let expected = {ancestorTitles: [] as Array}; expect(noAncestors).toEqual(expect.objectContaining(expected)); const addsNumbers = jsonResult.testResults[0].assertionResults.find( - item => item.title == 'adds numbers', + item => item.title === 'adds numbers', ); expected = {ancestorTitles: ['sum']}; expect(addsNumbers).toEqual(expect.objectContaining(expected)); const failsTheTest = jsonResult.testResults[0].assertionResults.find( - item => item.title == 'fails the test', + item => item.title === 'fails the test', ); expected = {ancestorTitles: ['sum', 'failing tests']}; expect(failsTheTest).toEqual(expect.objectContaining(expected)); diff --git a/packages/expect-utils/src/jasmineUtils.ts b/packages/expect-utils/src/jasmineUtils.ts index 870b6b0b9f18..e4f6bc176810 100644 --- a/packages/expect-utils/src/jasmineUtils.ts +++ b/packages/expect-utils/src/jasmineUtils.ts @@ -84,7 +84,7 @@ function eq( } if (a instanceof Error && b instanceof Error) { - return a.message == b.message; + return a.message === b.message; } if (Object.is(a, b)) { @@ -95,7 +95,7 @@ function eq( return false; } const className = Object.prototype.toString.call(a); - if (className != Object.prototype.toString.call(b)) { + if (className !== Object.prototype.toString.call(b)) { return false; } switch (className) { @@ -116,7 +116,7 @@ function eq( // Coerce dates to numeric primitive values. Dates are compared by their // millisecond representations. Note that invalid dates with millisecond representations // of `NaN` are not equivalent. - return +a == +b; + return +a === +b; // RegExps are compared by their source patterns and flags. case '[object RegExp]': return a.source === b.source && a.flags === b.flags; @@ -151,7 +151,7 @@ function eq( bStack.push(b); // Recursively compare objects and arrays. // Compare array lengths to determine if a deep comparison is necessary. - if (strictCheck && className == '[object Array]' && a.length !== b.length) { + if (strictCheck && className === '[object Array]' && a.length !== b.length) { return false; } diff --git a/packages/expect/src/asymmetricMatchers.ts b/packages/expect/src/asymmetricMatchers.ts index 92f7a67f539d..8eaa17d85bef 100644 --- a/packages/expect/src/asymmetricMatchers.ts +++ b/packages/expect/src/asymmetricMatchers.ts @@ -41,18 +41,6 @@ const utils = Object.freeze({ subsetEquality, }); -function getPrototype(obj: object) { - if (Object.getPrototypeOf) { - return Object.getPrototypeOf(obj); - } - - if (obj.constructor.prototype == obj) { - return null; - } - - return obj.constructor.prototype; -} - export function hasProperty( obj: object | null, property: string | symbol, @@ -65,7 +53,7 @@ export function hasProperty( return true; } - return hasProperty(getPrototype(obj), property); + return hasProperty(Object.getPrototypeOf(obj), property); } export abstract class AsymmetricMatcher @@ -108,35 +96,35 @@ class Any extends AsymmetricMatcher { } asymmetricMatch(other: unknown) { - if (this.sample == String) { - return typeof other == 'string' || other instanceof String; + if (this.sample === String) { + return typeof other === 'string' || other instanceof String; } - if (this.sample == Number) { - return typeof other == 'number' || other instanceof Number; + if (this.sample === Number) { + return typeof other === 'number' || other instanceof Number; } - if (this.sample == Function) { - return typeof other == 'function' || other instanceof Function; + if (this.sample === Function) { + return typeof other === 'function' || other instanceof Function; } - if (this.sample == Boolean) { - return typeof other == 'boolean' || other instanceof Boolean; + if (this.sample === Boolean) { + return typeof other === 'boolean' || other instanceof Boolean; } - if (this.sample == BigInt) { - return typeof other == 'bigint' || other instanceof BigInt; + if (this.sample === BigInt) { + return typeof other === 'bigint' || other instanceof BigInt; } - if (this.sample == Symbol) { - return typeof other == 'symbol' || other instanceof Symbol; + if (this.sample === Symbol) { + return typeof other === 'symbol' || other instanceof Symbol; } - if (this.sample == Object) { - return typeof other == 'object'; + if (this.sample === Object) { + return typeof other === 'object'; } - if (this.sample == Array) { + if (this.sample === Array) { return Array.isArray(other); } @@ -148,27 +136,27 @@ class Any extends AsymmetricMatcher { } override getExpectedType() { - if (this.sample == String) { + if (this.sample === String) { return 'string'; } - if (this.sample == Number) { + if (this.sample === Number) { return 'number'; } - if (this.sample == Function) { + if (this.sample === Function) { return 'function'; } - if (this.sample == Object) { + if (this.sample === Object) { return 'object'; } - if (this.sample == Boolean) { + if (this.sample === Boolean) { return 'boolean'; } - if (Array.isArray(this.sample)) { + if (this.sample === Array) { return 'array'; } diff --git a/packages/jest-haste-map/src/crawlers/__tests__/node.test.js b/packages/jest-haste-map/src/crawlers/__tests__/node.test.js index be9bdf2ba68a..d2e357c275ed 100644 --- a/packages/jest-haste-map/src/crawlers/__tests__/node.test.js +++ b/packages/jest-haste-map/src/crawlers/__tests__/node.test.js @@ -105,7 +105,7 @@ jest.mock('graceful-fs', () => { ]), 0, ); - } else if (slash(dir) == '/error') { + } else if (slash(dir) === '/error') { setTimeout(() => callback({code: 'ENOTDIR'}, undefined), 0); } }), diff --git a/packages/jest-repl/src/cli/runtime-cli.ts b/packages/jest-repl/src/cli/runtime-cli.ts index 335af1858dc1..5997b040a769 100644 --- a/packages/jest-repl/src/cli/runtime-cli.ts +++ b/packages/jest-repl/src/cli/runtime-cli.ts @@ -48,7 +48,7 @@ export async function run( return; } - if (argv.version == true) { + if (argv.version === true) { console.log(`v${VERSION}\n`); return; } diff --git a/packages/jest-reporters/src/wrapAnsiString.ts b/packages/jest-reporters/src/wrapAnsiString.ts index 233a53260140..10d77b2f265c 100644 --- a/packages/jest-reporters/src/wrapAnsiString.ts +++ b/packages/jest-reporters/src/wrapAnsiString.ts @@ -24,14 +24,14 @@ export default function wrapAnsiString( while ((match = ANSI_REGEXP.exec(string))) { const ansi = match[0]; const index = match.index; - if (index != lastIndex) { + if (index !== lastIndex) { tokens.push(['string', string.slice(lastIndex, index)]); } tokens.push(['ansi', ansi]); lastIndex = index + ansi.length; } - if (lastIndex != string.length - 1) { + if (lastIndex !== string.length - 1) { tokens.push(['string', string.slice(lastIndex, string.length)]); } diff --git a/packages/jest-test-sequencer/src/index.ts b/packages/jest-test-sequencer/src/index.ts index a0604eddc599..96e95035180c 100644 --- a/packages/jest-test-sequencer/src/index.ts +++ b/packages/jest-test-sequencer/src/index.ts @@ -202,9 +202,10 @@ export default class TestSequencer { const failedA = this.hasFailed(testA); const failedB = this.hasFailed(testB); const hasTimeA = testA.duration != null; + const hasTimeB = testB.duration != null; if (failedA !== failedB) { return failedA ? -1 : 1; - } else if (hasTimeA != (testB.duration != null)) { + } else if (hasTimeA !== hasTimeB) { // If only one of two tests has timing information, run it last return hasTimeA ? 1 : -1; } else if (testA.duration != null && testB.duration != null) { diff --git a/website/versioned_docs/version-29.4/ExpectAPI.md b/website/versioned_docs/version-29.4/ExpectAPI.md index 0e7a7a892799..bc205a987d60 100644 --- a/website/versioned_docs/version-29.4/ExpectAPI.md +++ b/website/versioned_docs/version-29.4/ExpectAPI.md @@ -811,7 +811,7 @@ For example, let's say that `drinkFlavor` is coded like this: ```js function drinkFlavor(flavor) { - if (flavor == 'octopus') { + if (flavor === 'octopus') { throw new DisgustingFlavorError('yuck, octopus flavor'); } // Do some other stuff @@ -849,7 +849,7 @@ For example, let's say you have a `drinkFlavor` function that throws whenever th ```js function drinkFlavor(flavor) { - if (flavor == 'octopus') { + if (flavor === 'octopus') { throw new DisgustingFlavorError('yuck, octopus flavor'); } // Do some other stuff @@ -1527,7 +1527,7 @@ expect.extend({ expect.extend({ async toBeDivisibleByExternalValue(received) { const externalValue = await getExternalValueFromRemoteSource(); - const pass = received % externalValue == 0; + const pass = received % externalValue === 0; if (pass) { return { message: () => diff --git a/website/versioned_docs/version-29.5/ExpectAPI.md b/website/versioned_docs/version-29.5/ExpectAPI.md index 0e7a7a892799..bc205a987d60 100644 --- a/website/versioned_docs/version-29.5/ExpectAPI.md +++ b/website/versioned_docs/version-29.5/ExpectAPI.md @@ -811,7 +811,7 @@ For example, let's say that `drinkFlavor` is coded like this: ```js function drinkFlavor(flavor) { - if (flavor == 'octopus') { + if (flavor === 'octopus') { throw new DisgustingFlavorError('yuck, octopus flavor'); } // Do some other stuff @@ -849,7 +849,7 @@ For example, let's say you have a `drinkFlavor` function that throws whenever th ```js function drinkFlavor(flavor) { - if (flavor == 'octopus') { + if (flavor === 'octopus') { throw new DisgustingFlavorError('yuck, octopus flavor'); } // Do some other stuff @@ -1527,7 +1527,7 @@ expect.extend({ expect.extend({ async toBeDivisibleByExternalValue(received) { const externalValue = await getExternalValueFromRemoteSource(); - const pass = received % externalValue == 0; + const pass = received % externalValue === 0; if (pass) { return { message: () => diff --git a/website/versioned_docs/version-29.6/ExpectAPI.md b/website/versioned_docs/version-29.6/ExpectAPI.md index 0e7a7a892799..bc205a987d60 100644 --- a/website/versioned_docs/version-29.6/ExpectAPI.md +++ b/website/versioned_docs/version-29.6/ExpectAPI.md @@ -811,7 +811,7 @@ For example, let's say that `drinkFlavor` is coded like this: ```js function drinkFlavor(flavor) { - if (flavor == 'octopus') { + if (flavor === 'octopus') { throw new DisgustingFlavorError('yuck, octopus flavor'); } // Do some other stuff @@ -849,7 +849,7 @@ For example, let's say you have a `drinkFlavor` function that throws whenever th ```js function drinkFlavor(flavor) { - if (flavor == 'octopus') { + if (flavor === 'octopus') { throw new DisgustingFlavorError('yuck, octopus flavor'); } // Do some other stuff @@ -1527,7 +1527,7 @@ expect.extend({ expect.extend({ async toBeDivisibleByExternalValue(received) { const externalValue = await getExternalValueFromRemoteSource(); - const pass = received % externalValue == 0; + const pass = received % externalValue === 0; if (pass) { return { message: () => diff --git a/website/versioned_docs/version-29.7/ExpectAPI.md b/website/versioned_docs/version-29.7/ExpectAPI.md index 0e7a7a892799..bc205a987d60 100644 --- a/website/versioned_docs/version-29.7/ExpectAPI.md +++ b/website/versioned_docs/version-29.7/ExpectAPI.md @@ -811,7 +811,7 @@ For example, let's say that `drinkFlavor` is coded like this: ```js function drinkFlavor(flavor) { - if (flavor == 'octopus') { + if (flavor === 'octopus') { throw new DisgustingFlavorError('yuck, octopus flavor'); } // Do some other stuff @@ -849,7 +849,7 @@ For example, let's say you have a `drinkFlavor` function that throws whenever th ```js function drinkFlavor(flavor) { - if (flavor == 'octopus') { + if (flavor === 'octopus') { throw new DisgustingFlavorError('yuck, octopus flavor'); } // Do some other stuff @@ -1527,7 +1527,7 @@ expect.extend({ expect.extend({ async toBeDivisibleByExternalValue(received) { const externalValue = await getExternalValueFromRemoteSource(); - const pass = received % externalValue == 0; + const pass = received % externalValue === 0; if (pass) { return { message: () =>