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