Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jestjs/jest
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: michkot/jest
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: addCustomDefaultEqualityTestersForExpectUtilsEqual
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Sep 19, 2022

  1. Attempt customization

    michkot committed Sep 19, 2022
    Copy the full SHA
    e748260 View commit details
Showing with 14 additions and 9 deletions.
  1. +3 −0 packages/expect/src/customDefaultEqualTesters.ts
  2. +9 −8 packages/expect/src/matchers.ts
  3. +2 −1 packages/expect/src/spyMatchers.ts
3 changes: 3 additions & 0 deletions packages/expect/src/customDefaultEqualTesters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

export const customDefaultEqualTesters = [
]
17 changes: 9 additions & 8 deletions packages/expect/src/matchers.ts
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ import {
printWithType,
stringify,
} from 'jest-matcher-utils';
import { customDefaultEqualTesters } from './customDefaultEqualTesters';
import {
printCloseTo,
printExpectedConstructorName,
@@ -97,9 +98,9 @@ const matchers: MatchersObject = {
if (expectedType !== 'map' && expectedType !== 'set') {
// If deep equality passes when referential identity fails,
// but exclude map and set until review of their equality logic.
if (equals(received, expected, toStrictEqualTesters, true)) {
if (equals(received, expected, [...customDefaultEqualTesters, ...toStrictEqualTesters], true)) {
deepEqualityName = 'toStrictEqual';
} else if (equals(received, expected, [iterableEquality])) {
} else if (equals(received, expected, [...customDefaultEqualTesters, iterableEquality])) {
deepEqualityName = 'toEqual';
}
}
@@ -540,7 +541,7 @@ const matchers: MatchersObject = {
}` +
(!isNot &&
indexable.findIndex(item =>
equals(item, expected, [iterableEquality]),
equals(item, expected, [...customDefaultEqualTesters, iterableEquality]),
) !== -1
? `\n\n${SUGGEST_TO_CONTAIN_EQUAL}`
: '')
@@ -570,7 +571,7 @@ const matchers: MatchersObject = {
}

const index = Array.from(received).findIndex(item =>
equals(item, expected, [iterableEquality]),
equals(item, expected, [...customDefaultEqualTesters, iterableEquality]),
);
const pass = index !== -1;

@@ -605,7 +606,7 @@ const matchers: MatchersObject = {
promise: this.promise,
};

const pass = equals(received, expected, [iterableEquality]);
const pass = equals(received, expected, [...customDefaultEqualTesters, iterableEquality]);

const message = pass
? () =>
@@ -748,7 +749,7 @@ const matchers: MatchersObject = {

const pass =
hasValue && endPropIsDefined
? equals(value, expectedValue, [iterableEquality])
? equals(value, expectedValue, [...customDefaultEqualTesters, iterableEquality])
: Boolean(hasEndProp);

const message = pass
@@ -896,7 +897,7 @@ const matchers: MatchersObject = {
);
}

const pass = equals(received, expected, [iterableEquality, subsetEquality]);
const pass = equals(received, expected, [...customDefaultEqualTesters, iterableEquality, subsetEquality]);

const message = pass
? () =>
@@ -930,7 +931,7 @@ const matchers: MatchersObject = {
promise: this.promise,
};

const pass = equals(received, expected, toStrictEqualTesters, true);
const pass = equals(received, expected, [...customDefaultEqualTesters, ...toStrictEqualTesters], true);

const message = pass
? () =>
3 changes: 2 additions & 1 deletion packages/expect/src/spyMatchers.ts
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ import {
printWithType,
stringify,
} from 'jest-matcher-utils';
import { customDefaultEqualTesters } from './customDefaultEqualTesters';
import type {
MatcherState,
MatchersObject,
@@ -59,7 +60,7 @@ const printReceivedArgs = (
const printCommon = (val: unknown) => DIM_COLOR(stringify(val));

const isEqualValue = (expected: unknown, received: unknown): boolean =>
equals(expected, received, [iterableEquality]);
equals(expected, received, [...customDefaultEqualTesters, iterableEquality]);

const isEqualCall = (
expected: Array<unknown>,