import test from 'ava' import Window from 'window'; import documentOuterHTML from '../src' function makeDocument(html) { const window = new Window() const parser = new window.DOMParser() const doc = parser.parseFromString( html, 'text/html' ) return doc } function normalise(html) { // Remove whitespace around string and between tags. return html.trim().replace(/>\s+<') } test('should work with only an html node', t => { const html = `

blub.

` const doc = makeDocument(html) t.is( normalise(documentOuterHTML(doc)), normalise(html) ) }) test('should work with comments', t => { const html = `

blub.

` const doc = makeDocument(html) t.is( normalise(documentOuterHTML(doc)), normalise(html) ) }) test('should work with doctype', t => { const html = `

blub.

` const doc = makeDocument(html) t.is( normalise(documentOuterHTML(doc)), normalise(html) ) }) test('should work without a documentElement', t => { const html = ` ` const doc = makeDocument(html) // The html (+head&body) element will have been created automatically. Remove it. doc.removeChild(doc.documentElement) t.is( normalise(documentOuterHTML(doc)), normalise(html) ) }) test('should even work on a completely empty document', t => { const html = `` const doc = makeDocument(html) // The html (+head&body) element will have been created automatically. Remove it. doc.removeChild(doc.documentElement) t.is( normalise(documentOuterHTML(doc)), normalise(html) ) })