Commit 74f9b842 authored by David Sveningsson's avatar David Sveningsson
Browse files

fix(jest): handle when `jest-diff` default import is object

parent 7957fc5e
Pipeline #373175100 passed with stages
in 12 minutes and 3 seconds
......@@ -13,9 +13,23 @@ interface TokenMatcher {
data?: any;
}
/* ignore typing for compatibility so it will seem "impossible" but different version will yield different source */
const diffCandidates: Array<typeof jestDiff.diff> = [
// @ts-ignore
jestDiffDefault?.diff,
// @ts-ignore
jestDiffDefault,
// @ts-ignore
jestDiff?.diff,
// @ts-ignore
jestDiff,
];
const isFunction = (fn: unknown): boolean => typeof fn === "function";
/* istanbul ignore next: covered by compatibility tests but not a single pass */
/* @ts-ignore typing for compatibility so it will seem "impossible" but different version will yield different source */
const diff: typeof jestDiff.diff = jestDiffDefault ?? jestDiff?.diff ?? jestDiff;
/* @ts-ignore assume one of the candidate matches, there will be a reasonable error later on if not */
const diff: typeof jestDiff.diff = diffCandidates.find(isFunction);
declare global {
namespace jest {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment