UNPKG

4.75 kBHTMLView Raw
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="UTF-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 <meta http-equiv="X-UA-Compatible" content="ie=edge">
7 <title>Document</title>
8 <link href="https://unpkg.com/mocha@4.0.1/mocha.css" rel="stylesheet" />
9 <link rel="stylesheet" href="/test/styles.css">
10</head>
11<body>
12 <nav onclick="location.pathname='/test/index.html'">
13 <h1>Mocha Tests - Composi h Function</h1>
14 </nav>
15 <section>
16 <div id="mocha"></div>
17 <div id="messages"></div>
18 <div id="fixtures"></div>
19 </section>
20
21 <script src='/dist/composi.js'></script>
22 <script src="https://unpkg.com/mocha@4.0.1/mocha.js"></script>
23 <script src="https://unpkg.com/chai@4.1.2/chai.js"></script>
24 <script>mocha.setup('bdd')</script>
25 <script>
26 const {h, render, patch} = composi
27 let expect = chai.expect
28
29 const h1 = h('h1')
30 const title = h('h1', {id: 'title'}, 'The Title')
31
32 const list = h(
33 'ul',
34 {
35 class: 'list'
36 },
37 [
38 h('li', null, 'one'),
39 h('li', null, 'two'),
40 h('li', null, 'three')
41 ]
42 )
43
44 const alert = h(
45 'h2',
46 {
47 style: 'color: red;'
48 },
49 "Alert!"
50 )
51
52 describe("Test for var h1 = h('h1')", function() {
53 it('h1 should have type "h1"', function() {
54 expect(h1.type).to.equal('h1')
55 });
56 it('h1 should have {} for props', function() {
57 expect(JSON.stringify(h1.props)).to.equal('{}')
58 });
59 it('h1 should have no children', function() {
60 expect(h1.children).to.have.lengthOf(0);
61 });
62 });
63 describe("Test for var title = h('h1', {id: 'title'}).to.equal('The Title')", function() {
64 it('title should have type "h1"', function() {
65 expect(title.type).to.equal('h1')
66 })
67 it('title should have prop of id equal to "title"', function() {
68 expect(title.props.id).to.equal('title')
69 })
70 it('title should have one child', function() {
71 expect(title.children).to.have.lengthOf(1)
72 })
73 it('title child should be "The Title"', function() {
74 expect(title.children[0]).to.equal('The Title')
75 })
76 })
77 describe('h should accept a functional component that takes props and children and returns a virtual node.', function() {
78 const Component = (props, children) => h("div", props, children)
79 const result = h(Component, null, "foo")
80 it('Functional component should be {type: "div", props: {}, children: ["foo"]}', function() {
81 expect(JSON.stringify(result)).to.equal(JSON.stringify({type: "div", props: {}, children: ["foo"]}))
82 })
83 })
84 describe("Test for creation of list", function() {
85 it('list should have type "ul"', function() {
86 expect(list.type).to.equal('ul')
87 })
88 it('list should have prop of class equal to "list"', function() {
89 expect(list.props.class).to.equal('list')
90 })
91 it('list should have three children', function() {
92 expect(list.children).to.have.lengthOf(3)
93 })
94 it('list child 1 should have type of "li"', function() {
95 expect(list.children[0].type).to.equal('li')
96 })
97 it('list child 2 should have type of "li"', function() {
98 expect(list.children[1].type).to.equal('li')
99 })
100 it('list child 3 should have type of "li"', function() {
101 expect(list.children[2].type).to.equal('li')
102 })
103 it('list child 1 props should be {}', function() {
104 expect(JSON.stringify(list.children[0].props)).to.equal('{}')
105 })
106 it('list child 2 props should be {}', function() {
107 expect(JSON.stringify(list.children[1].props)).to.equal('{}')
108 })
109 it('list child 3 props should be {}', function() {
110 expect(JSON.stringify(list.children[2].props)).to.equal('{}')
111 })
112 it('list child 1 should be "one"', function() {
113 expect(list.children[0].children[0]).to.equal('one')
114 })
115 it('list child 2 should be "two"', function() {
116 expect(list.children[1].children[0]).to.equal('two')
117 })
118 it('list child 3 should be "one"', function() {
119 expect(list.children[2].children[0]).to.equal('three')
120 })
121 })
122 describe("Test for style property: var alert = h('h2',{style: 'color: red;'},\"Alert!\")", function() {
123 it('alert type should be "h2"', function() {
124 expect(alert.type).to.equal("h2")
125 })
126 it('alert style should be "color: red;"', function() {
127 expect(alert.props.style).to.equal('color: red;')
128 })
129 it('alert child should be "Alert!"', function() {
130 expect(alert.children[0]).to.equal("Alert!")
131 })
132 })
133
134 mocha.run()
135 </script>
136</body>
137</html>
\No newline at end of file