|
12345678910111213141516171819202122232425262728293031323334353637383940 |
- 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}<html></html>`,
- '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 = '<!DOCTYPE html>'
- const doc = makeStubDocument(doctype)
- t.is(doctypeToString(doc.doctype), doctype)
- })
-
- test('should work for a HTML4-ish doctype', t => {
- const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
- const doc = makeStubDocument(doctype)
- t.is(doctypeToString(doc.doctype), doctype)
- })
-
- test('should work for a doctype without public id', t => {
- const doctype = '<!DOCTYPE html SYSTEM "http://www.w3.org/TR/html4/loose.dtd">'
- const doc = makeStubDocument(doctype)
- t.is(doctypeToString(doc.doctype), doctype)
- })
|