UNPKG

cypress-ct-lit

Version:
38 lines (37 loc) 1.24 kB
import { getContainerEl, setupHooks } from '@cypress/mount-utils'; import { render, nothing, html } from 'lit'; import { unsafeHTML } from 'lit/directives/unsafe-html.js'; let dispose; function cleanup() { dispose === null || dispose === void 0 ? void 0 : dispose(); } export function mount(template, options = {}) { cleanup(); const root = getContainerEl(); const value = typeof template === 'string' ? html `${unsafeHTML(template)}` : template; render(value, root, options.render); dispose = () => { render(nothing, root); }; return cy .wrap(root, { log: false }) .wait(0, { log: false }) .children({ log: false }) .first({ log: false }) .then((element) => { const name = element.prop("tagName").toLowerCase(); // safe cast for current html element const el = document.getElementsByTagName(name)[0]; if (options.log !== false) { Cypress.log({ name: 'mount', displayName: 'mount', message: `<${name} ... />` }) .snapshot('mounted') .end(); } return cy.wrap(el, { log: false }); }); } setupHooks(cleanup);