import test from 'ava' import Window from 'window'; import doctypeToString from '../src' function makeStubDocument(doctype) { const window = new Window() const parser = new window.DOMParser() const doc = parser.parseFromString( `${doctype}`, 'text/html' ) return doc } test('should return empty string if doctype is null', t => { t.is(doctypeToString(null), '') }) test('should throw if argument is not a DocumentType', t => { t.throws(() => doctypeToString('a string, for example.'), TypeError) }) test('should work for a HTML5-ish doctype', t => { const doctype = '' const doc = makeStubDocument(doctype) t.is(doctypeToString(doc.doctype), doctype) }) test('should work for a HTML4-ish doctype', t => { const doctype = '' const doc = makeStubDocument(doctype) t.is(doctypeToString(doc.doctype), doctype) }) test('should work for a doctype without public id', t => { const doctype = '' const doc = makeStubDocument(doctype) t.is(doctypeToString(doc.doctype), doctype) })