Skip to content

Commit 74f9b84

Browse files
committed
fix(jest): handle when jest-diff default import is object
1 parent 7957fc5 commit 74f9b84

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/matchers.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,23 @@ interface TokenMatcher {
1313
data?: any;
1414
}
1515

16+
/* ignore typing for compatibility so it will seem "impossible" but different version will yield different source */
17+
const diffCandidates: Array<typeof jestDiff.diff> = [
18+
// @ts-ignore
19+
jestDiffDefault?.diff,
20+
// @ts-ignore
21+
jestDiffDefault,
22+
// @ts-ignore
23+
jestDiff?.diff,
24+
// @ts-ignore
25+
jestDiff,
26+
];
27+
28+
const isFunction = (fn: unknown): boolean => typeof fn === "function";
29+
1630
/* istanbul ignore next: covered by compatibility tests but not a single pass */
17-
/* @ts-ignore typing for compatibility so it will seem "impossible" but different version will yield different source */
18-
const diff: typeof jestDiff.diff = jestDiffDefault ?? jestDiff?.diff ?? jestDiff;
31+
/* @ts-ignore assume one of the candidate matches, there will be a reasonable error later on if not */
32+
const diff: typeof jestDiff.diff = diffCandidates.find(isFunction);
1933

2034
declare global {
2135
namespace jest {

0 commit comments

Comments
 (0)