|
1234567891011121314151617181920212223242526272829303132333435363738 |
- 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 absent', t => {
- const doctype = ''
- const doc = makeStubDocument()
- t.is(doctypeToString(doc.doctype), doctype)
- })
-
- 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)
- })
|