test: add testing framework
This commit is contained in:
parent
bbfd2f5711
commit
99ae3402a5
12 changed files with 563 additions and 24 deletions
64
test/test-suites/rendering.tsx
Normal file
64
test/test-suites/rendering.tsx
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/* 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(<div />)).toThrowErrorMatching(
|
||||
"attempted to render page with non-HTML root element div"
|
||||
);
|
||||
});
|
||||
|
||||
test("outputs a HTML5 DOCTYPE declaration", () => {
|
||||
const html = renderPage(<html />);
|
||||
expect(html).toStartWith("<!DOCTYPE html>");
|
||||
});
|
||||
|
||||
test("escapes HTML in tag names", () => {
|
||||
const html = renderPage(
|
||||
<html>{createElement("div></div", null)}</html>
|
||||
);
|
||||
expect(html).toEqual(
|
||||
"<!DOCTYPE html><html><div></div></div></div></html>"
|
||||
);
|
||||
});
|
||||
|
||||
test("renders html attributes", () => {
|
||||
const html = renderPage(
|
||||
<html>
|
||||
<div className="test" id="1" />
|
||||
</html>
|
||||
);
|
||||
expect(html).toEqual(
|
||||
'<!DOCTYPE html><html><div class="test" id="1"></div></html>'
|
||||
);
|
||||
});
|
||||
|
||||
test("renders common html tags", () => {
|
||||
const html = renderPage(
|
||||
<html>
|
||||
<head>
|
||||
<title />
|
||||
</head>
|
||||
<body>
|
||||
<div />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
expect(html).toEqual(
|
||||
"<!DOCTYPE html><html><head><title></title></head><body><div></div></body></html>"
|
||||
);
|
||||
});
|
||||
|
||||
test("renders text nodes", () => {
|
||||
const html = renderPage(<html>There are three lights!</html>);
|
||||
expect(html).toEqual(
|
||||
"<!DOCTYPE html><html>There are three lights!</html>"
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue