This repository was archived by the owner on Dec 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
52 lines (40 loc) · 1.38 KB
/
test.js
File metadata and controls
52 lines (40 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const assert = require("assert");
const equal = target => source => assert.equal(source, target);
const pass = str => () => console.log(`> [info] Test passed! ${str}`);
const error = (str = "") => err => {
console.error(`> [err] Test failed! ${str}`);
process.exitCode = 1;
throw err;
};
if (!global.window) {
global.window = global.document = global.requestAnimationFrame = undefined;
}
const render = require("mithril-node-render");
const { elements, maybe } = require("./dist");
const { html, head, body, div, h1, h2, p } = elements;
const testHTML =
'<html><head></head><body class="container"><div id="id" class="hello world"><h1 id="main-title" class="title">Hello World</h1><h2>Subheading</h2><p>This is some text</p></div></body></html>';
const empty = "";
render(
html(
head(),
body[".container"][maybe(5 === "5" && "classname")](
div.hello.world[empty][maybe(5 === 5 && "#id")](
h1.title["#main-title"]("Hello World"),
h2("Subheading"),
p("This is some text"),
),
),
),
)
.then(equal(testHTML))
.then(pass("Renders HTML correctly"))
.catch(error("Render failed"));
Promise.resolve(elements.html)
.then(equal(elements.html))
.then(pass("Elements are cached"))
.catch(error("Elements are not cached"));
Promise.resolve(elements.html.a.b)
.then(equal(elements.html.a.b))
.then(error("MithrilScript was cached!"))
.catch(pass("MithrilScript was not cached"));