Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add support for custom equality testers #13654

Merged
merged 30 commits into from Jan 3, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/expect/__typetests__/expect.test.ts
Expand Up @@ -6,12 +6,14 @@
*/

import {expectAssignable, expectError, expectType} from 'tsd-lite';
import type {EqualsFunction, Tester, TesterContext} from '@jest/expect-utils';
import type {EqualsFunction} from '@jest/expect-utils';
import {
MatcherContext,
MatcherFunction,
MatcherFunctionWithContext,
Matchers,
Tester,
TesterContext,
expect,
} from 'expect';
Comment on lines +15 to 18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This re-export looks right. Thanks!

import type * as jestMatcherUtils from 'jest-matcher-utils';
Expand All @@ -22,8 +24,18 @@ expectError(() => {
type E = Matchers;
});

const tester1: Tester = function (a, b, customTesters) {
expectType<any>(a);
expectType<any>(b);
expectType<Array<Tester>>(customTesters);
expectType<TesterContext>(this);
expectType<EqualsFunction>(this.equals);
return undefined;
};

expectType<void>(
expect.addEqualityTesters([
tester1,
(a, b, customTesters) => {
expectType<any>(a);
expectType<any>(b);
Expand Down
3 changes: 1 addition & 2 deletions packages/expect/src/index.ts
Expand Up @@ -53,6 +53,7 @@ import type {
ThrowingMatcherFn,
} from './types';

export type {Tester, TesterContext} from '@jest/expect-utils';
export {AsymmetricMatcher} from './asymmetricMatchers';
export type {
AsyncExpectationResult,
Expand All @@ -69,8 +70,6 @@ export type {
SyncExpectationResult,
} from './types';

// TODO: Re-export Tester and TestContext?

export class JestAssertionError extends Error {
matcherResult?: Omit<SyncExpectationResult, 'message'> & {message: string};
}
Expand Down