UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

40 lines (28 loc) 1.35 kB
StartTest(function(t) { t.beforeEach(function (t) { document.body.innerHTML = ''; }); t.it('nodeIsOrphan', function(t) { const template = document.createElement('template'); template.innerHTML = '<div></div>'; class TodoApp extends HTMLElement { constructor() { super(); this._shadowRoot = this.attachShadow({ 'mode': 'open' }); this._shadowRoot.appendChild(template.content.cloneNode(true)); } } window.customElements.define('todo-app', TodoApp); var app = document.createElement('todo-app'); document.body.appendChild(app); const orphan = document.createElement('div'); t.notOk(t.nodeIsOrphan(document.documentElement), 'document.documentElement is not orphan'); t.notOk(t.nodeIsOrphan(document.body), 'body is orphan'); t.notOk(t.nodeIsOrphan(app), 'web component el is not orphan'); t.notOk(t.nodeIsOrphan(app.shadowRoot.querySelector('div')), 'web component child el is not orphan'); app.remove(); t.ok(t.nodeIsOrphan(orphan), 'detached node is orphan'); t.ok(t.nodeIsOrphan(app), 'detached web component node is orphan'); t.ok(t.nodeIsOrphan(app.shadowRoot), 'detached web component shadowRoot is orphan'); }); })