Skip to content

Commit

Permalink
Merge branch 'main' into fix-14317
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Jul 12, 2024
2 parents e3e119d + afd1c20 commit 7e7666c
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions docs/ExpectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: () =>
Expand Down
14 changes: 7 additions & 7 deletions e2e/__tests__/jsonReporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>};
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);
});
Expand Down Expand Up @@ -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<string>};
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));
Expand Down
8 changes: 4 additions & 4 deletions packages/expect-utils/src/jasmineUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
56 changes: 22 additions & 34 deletions packages/expect/src/asymmetricMatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -65,7 +53,7 @@ export function hasProperty(
return true;
}

return hasProperty(getPrototype(obj), property);
return hasProperty(Object.getPrototypeOf(obj), property);
}

export abstract class AsymmetricMatcher<T>
Expand Down Expand Up @@ -108,35 +96,35 @@ class Any extends AsymmetricMatcher<any> {
}

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);
}

Expand All @@ -148,27 +136,27 @@ class Any extends AsymmetricMatcher<any> {
}

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';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-repl/src/cli/runtime-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function run(
return;
}

if (argv.version == true) {
if (argv.version === true) {
console.log(`v${VERSION}\n`);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-reporters/src/wrapAnsiString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)]);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/jest-test-sequencer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions website/versioned_docs/version-29.4/ExpectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: () =>
Expand Down
6 changes: 3 additions & 3 deletions website/versioned_docs/version-29.5/ExpectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: () =>
Expand Down
6 changes: 3 additions & 3 deletions website/versioned_docs/version-29.6/ExpectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: () =>
Expand Down
6 changes: 3 additions & 3 deletions website/versioned_docs/version-29.7/ExpectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: () =>
Expand Down

0 comments on commit 7e7666c

Please sign in to comment.