Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
expect.extend({
toMatchSnapshot(ctx) {
if (!ctx || !ctx.test) {
throw new Error(
dedent(`missing \`ctx\` parameter for .toMatchSnapshot(),
did you forget to pass \`this\` expect().toMatchSnapshot(this)?`),
);
}
const { test } = ctx;
// would contain the full path to test file
const testFile = test.file;
const testTitle = makeTestTitle(test);
const result = toMatchSnapshot(this.actual, testFile, testTitle);
expect.assert(result.pass, !result.pass ? result.report() : '');
return this;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment