-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.spec.js
99 lines (96 loc) · 2.67 KB
/
index.spec.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var assert = require('assert');
var ReactDOMServer = require('react-dom/server');
var React = require('react');
var render = ReactDOMServer.renderToStaticMarkup;
var Heact = require('../');
describe('create w/o namespace', function () {
var h = Heact();
it('works for simple div', function () {
assert.equal(
render(h('div')),
'<div></div>'
);
});
it('uses div by default', function () {
assert.equal(
render(h('')),
'<div></div>'
);
});
it('adds class', function () {
assert.equal(
render(h('div.foo')),
'<div class="foo"></div>'
);
});
it('uses default tag div with class', function () {
assert.equal(
render(h('.foo')),
'<div class="foo"></div>'
);
});
it('add all classes', function () {
assert.equal(
render(h('div.foo.bar')),
'<div class="foo bar"></div>'
);
});
it('pass tag name to original createElement', function () {
assert.equal(
render(h('span')),
'<span></span>'
);
});
it('pass rest arguments to original', function () {
assert.equal(
render(h('div', null, h('span'))),
'<div><span></span></div>'
);
});
it('concatenetes class from tag to prop', function () {
assert.equal(
render(h('div.foo', {
className: 'bar'
})),
'<div class="bar foo"></div>'
);
});
it('allows to use non-string elements', function () {
var elem = React.createClass({
render: function () {
return h('div');
}
});
assert.equal(
render(h(elem)),
'<div></div>'
);
});
it.skip('perf: ~80% of orig speed', function () {
this.timeout(20000);
var start = process.hrtime();
for (i = 0; i < 10000; i++) {
render(h('.foo'));
}
var a = process.hrtime(start);
var aNano = a[0] * 1e9 + a[1];
start = process.hrtime();
for (var i = 0; i < 10000; i++) {
render(React.createElement('div', {
className: 'foo'
}));
}
var b = process.hrtime(start);
var bNano = b[0] * 1e9 + b[1];
console.log('%d % of original speed', ~~(bNano / aNano * 100));
});
});
describe('create with namespace', function () {
var h = Heact('.ns');
it('add namespace as last class', function () {
assert.equal(
render(h('div')),
'<div class="ns"></div>'
);
});
});