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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: avoid deprecated jest.addMatchers #12811

Merged
merged 1 commit into from Feb 16, 2021
Merged
Changes from all commits
Commits
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
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");
Copy link
Contributor

Choose a reason for hiding this comment

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

can check this.isNot and throw earlier. doesn't matter in practice I guess

}
: () => {
const diffString = diff(code, actual, {
Copy link
Contributor

@SimenB SimenB Feb 18, 2021

Choose a reason for hiding this comment

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

this uses an imported jest-diff, can just do this.utils.diff instead and not have to have a dependency on jest-diff

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({
Copy link
Contributor

Choose a reason for hiding this comment

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

sorta weird to extend inside the describe and not at the top level

toEqualFile,
});

Expand Down