/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import { createElement } from "../../dist"; import { renderPage } from "../../dist/render"; import { testSuite } from "../lib"; testSuite("renderPage", ({ test, expect }) => { test("throws an Error when root elem is not html tag", () => { expect(() => renderPage(
)).toThrowErrorMatching( "attempted to render page with non-HTML root element div" ); }); test("outputs a HTML5 DOCTYPE declaration", () => { const html = renderPage(); expect(html).toStartWith(""); }); test("escapes HTML in tag names", () => { const html = renderPage( {createElement("div> ); expect(html).toEqual( "" ); }); test("renders html attributes", () => { const html = renderPage(
); expect(html).toEqual( '
' ); }); test("renders common html tags", () => { const html = renderPage( </head> <body> <div /> </body> </html> ); expect(html).toEqual( "<!DOCTYPE html><html><head><title>
" ); }); test("renders text nodes", () => { const html = renderPage(There are three lights!); expect(html).toEqual( "There are three lights!" ); }); test("renders spliced number nodes", () => { const nLights = 3; const html = renderPage(There are {nLights} lights!); expect(html).toEqual("There are 3 lights!"); }); });