Skip to content

Instantly share code, notes, and snippets.

@edgerunner
Created December 21, 2018 01:09
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 edgerunner/d83ab9cc5eaa4c7b2c558a41e8a4f01e to your computer and use it in GitHub Desktop.
Save edgerunner/d83ab9cc5eaa4c7b2c558a41e8a4f01e to your computer and use it in GitHub Desktop.
Cypress command to mount react components
import { render } from "react-dom";
Cypress.Commands.add("mount", (component) => {
cy.get("body", { log: false }).then((body) => {
body[0].innerText="";
const container = document.createElement("div");
container.setAttribute("id", "cypress");
body[0].appendChild(container);
render(component, container);
return container;
});
Cypress.log({ message: component.type.name, consoleProps: () => ({ Component: component }) });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment