Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
63d7186
Add customEqualityTesters support to toEqual
andrewiggins Dec 1, 2022
8f1daca
Add support for custom testers in iterableEquality
andrewiggins Dec 1, 2022
45243cd
Add customTester support to toContainEqual and toHaveProperty
andrewiggins Dec 1, 2022
cb73a20
Add customTester support toStrictEqual
andrewiggins Dec 1, 2022
ce6aca4
Add customTester support to toMatchObject
andrewiggins Dec 1, 2022
b5684ce
Add customTesters to asymmetric matchers
andrewiggins Dec 1, 2022
2fa1336
Add customTesters to spy matchers
andrewiggins Dec 1, 2022
e414bcc
Add test for custom matcher
andrewiggins Dec 1, 2022
944934f
Clean up new tests a bit
andrewiggins Dec 1, 2022
8a8bc17
Add support for customTesters to matcher recommendations in errors
andrewiggins Dec 1, 2022
1ee862f
Give custom testers higher priority over built-in testers
andrewiggins Dec 1, 2022
3961c37
Add custom testers to getObjectSubset
andrewiggins Dec 1, 2022
7bdcded
Add CHANGELOG entry
andrewiggins Dec 1, 2022
144f351
Fix customEqualityTesters TS errors
andrewiggins Dec 1, 2022
1c9b629
Update packages/expect/src/__tests__/customEqualityTesters.test.ts
andrewiggins Dec 2, 2022
9998279
Change API to addEqualityTesters
andrewiggins Dec 16, 2022
9fcf9b5
Get customTesters from matcherContext
andrewiggins Dec 16, 2022
a791dcb
Rename customTesters to filteredCustomTesters
andrewiggins Dec 16, 2022
32d0e38
Add type tests for new API
andrewiggins Dec 16, 2022
05eca9f
Merge branch 'main' into custom-tester-extensions
SimenB Jan 1, 2023
b72796b
Merge branch 'main' into custom-tester-extensions
andrewiggins Jan 1, 2023
c9dc27c
Add docs, pt. 1
andrewiggins Jan 2, 2023
d22295b
Reorganize code to obsolete eslint ignore
andrewiggins Jan 2, 2023
8591181
Convert custom equal testers tests to use Volume object matching docs
andrewiggins Jan 2, 2023
e88fff2
Finish out ExpectAPI docs and add recursive equality tester test
andrewiggins Jan 2, 2023
bed9a1e
reorganize
SimenB Jan 2, 2023
15e509c
link in changelog
SimenB Jan 2, 2023
96de10d
link section
SimenB Jan 2, 2023
dea4949
Expose equals function on tester context
andrewiggins Jan 3, 2023
90afadb
Re-export Tester and TesterContext in expect package
andrewiggins Jan 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add customTester support toStrictEqual
  • Loading branch information
andrewiggins committed Dec 1, 2022
commit cb73a206e3c4abdae5959894589ab7b90b764f9e
9 changes: 7 additions & 2 deletions packages/expect-utils/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,10 @@ export const arrayBufferEquality = (
return true;
};

// TODO: Update with customTesters
export const sparseArrayEquality = (
a: unknown,
b: unknown,
customTesters: Array<Tester> = [],
): boolean | undefined => {
if (!Array.isArray(a) || !Array.isArray(b)) {
return undefined;
Expand All @@ -378,7 +378,12 @@ export const sparseArrayEquality = (
const aKeys = Object.keys(a);
const bKeys = Object.keys(b);
return (
equals(a, b, [iterableEquality, typeEquality], true) && equals(aKeys, bKeys)
equals(
a,
b,
customTesters.filter(t => t !== sparseArrayEquality),
true,
) && equals(aKeys, bKeys)
);
};

Expand Down
21 changes: 12 additions & 9 deletions packages/expect/src/__tests__/customEqualityTesters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ it('has no custom testers as default', () => {
const special1 = createSpecialObject(1);
const special2 = createSpecialObject(2);

// Basic matchers passing
// Basic matchers passing with default settings
expect(special1).toBe(special1);
expect(special1).toEqual(special1);
expect([special1, special2]).toEqual([special1, special2]);
Expand All @@ -69,7 +69,7 @@ it('has no custom testers as default', () => {
toIterator([special1, special2]),
);

// Basic matchers not passing
// Basic matchers not passing with default settings
expect(special1).not.toBe(special2);
expect(createSpecialObject(1)).not.toEqual(createSpecialObject(2));
expect([special1, special2]).not.toEqual([special2, special1]);
Expand All @@ -80,6 +80,10 @@ it('has no custom testers as default', () => {
expect(toIterator([special1, special2])).not.toEqual(
toIterator([special2, special1]),
);
expect({a: special1, b: undefined}).not.toStrictEqual({
a: special2,
b: undefined,
});
});

describe('with custom equality testers', () => {
Expand Down Expand Up @@ -117,15 +121,14 @@ describe('with custom equality testers', () => {
expect(toIterator([special1, special2])).toEqual(
toIterator([special2, special1]),
);
expect([createSpecialObject(1)]).toContainEqual(createSpecialObject(2));
expect({a: createSpecialObject(1)}).toHaveProperty(
'a',
createSpecialObject(2),
);
expect([special1]).toContainEqual(special2);
expect({a: special1}).toHaveProperty('a', special2);
expect({a: special1, b: undefined}).toStrictEqual({
a: special2,
b: undefined,
});
});

// it('applies custom testers to toStrictEqual', () => {});

// it('applies custom testers to toMatchObject', () => {});

// TODO: Add tests for other matchers
Expand Down
7 changes: 6 additions & 1 deletion packages/expect/src/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,12 @@ const matchers: MatchersObject = {
promise: this.promise,
};

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

const message = pass
? () =>
Expand Down