Skip to content

Instantly share code, notes, and snippets.

@alexbeletsky
Created January 26, 2018 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexbeletsky/449a22de174aae6ec614410ba7589878 to your computer and use it in GitHub Desktop.
Save alexbeletsky/449a22de174aae6ec614410ba7589878 to your computer and use it in GitHub Desktop.
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