Skip to content

Commit

Permalink
test: avoid deprecated jest.addMatchers (#12811)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeysal committed Feb 16, 2021
1 parent 8e9143f commit 0bb5700
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions packages/babel-helper-transform-fixture-test-runner/src/index.js
Expand Up @@ -342,27 +342,26 @@ function normalizeOutput(code) {
return result;
}

const toEqualFile = () => ({
compare: (actual, { filename, code }) => {
const pass = actual === code;
return {
pass,
message: () => {
const diffString = diff(code, actual, {
expand: false,
});
return (
`Expected ${filename} to match transform output.\n` +
`To autogenerate a passing version of this file, delete the file and re-run the tests.\n\n` +
`Diff:\n\n${diffString}`
);
},
};
},
negativeCompare: () => {
throw new Error("Negation unsupported");
},
});
const toEqualFile = (actual, { filename, code }) => {
const pass = actual === code;
return {
pass,
message: pass
? () => {
throw new Error(".toEqualFile does not support negation");
}
: () => {
const diffString = diff(code, actual, {
expand: false,
});
return (
`Expected ${filename} to match transform output.\n` +
`To autogenerate a passing version of this file, delete the file and re-run the tests.\n\n` +
`Diff:\n\n${diffString}`
);
},
};
};

export default function (
fixturesLoc: string,
Expand All @@ -377,7 +376,7 @@ export default function (
if (suiteOpts.ignoreSuites?.includes(testSuite.title)) continue;

describe(name + "/" + testSuite.title, function () {
jest.addMatchers({
expect.extend({
toEqualFile,
});

Expand Down

0 comments on commit 0bb5700

Please sign in to comment.