Skip to content

Instantly share code, notes, and snippets.

@joeybeninghove
Last active December 16, 2020 03:58
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 joeybeninghove/c4e5cd64be4cb71d8c0b3f5c537c76f6 to your computer and use it in GitHub Desktop.
Save joeybeninghove/c4e5cd64be4cb71d8c0b3f5c537c76f6 to your computer and use it in GitHub Desktop.
toHaveCssClass custom matcher for jest-dom
expect.extend({
toHaveCssClass(received, cssClass) {
const pass = received.querySelector(`.${cssClass}`) !== undefined;
return {
message: () => this.isNot ? `${cssClass} was found` : `${cssClass} not found`,
pass: pass
};
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment