-
Notifications
You must be signed in to change notification settings - Fork 5
/
NoJsxSpec.js
65 lines (55 loc) · 1.85 KB
/
NoJsxSpec.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
"use strict";
var React = require("react");
var noJsxMixin = require("../mixin");
var TestSubComponent = React.createClass({
mixins: [noJsxMixin],
renderTree: function () {
return ["li", { className: "list__item" },
this.props.text,
" ",
["a.list__link", { href: "#open" }, "open"],
];
},
});
var TestComponent = React.createClass({
mixins: [noJsxMixin],
renderList: function () {
return ["foo", 5, "meow"].map(function (value) {
return [TestSubComponent, { key: value, text: value },
];
});
},
renderTree: function () {
return ["ul#list_main", { className: "list" },
this.renderList(),
[],
null,
];
},
});
var TestBasicComponent = React.createClass({
mixins: [noJsxMixin],
renderTree: function () {
return ["div",
["h1", "Foo"],
["p", "Bar"],
];
},
});
describe("no-jsx mixin", function () {
it("should convert the items returned by renderTree() to React elements", function () {
var result = React.renderToStaticMarkup(React.createElement(TestComponent, {}));
result.should.equal("<ul class=\"list\" id=\"list_main\">" +
"<li class=\"list__item\">foo <a href=\"#open\" class=\"list__link\">open</a></li>" +
"<li class=\"list__item\">5 <a href=\"#open\" class=\"list__link\">open</a></li>" +
"<li class=\"list__item\">meow <a href=\"#open\" class=\"list__link\">open</a></li>" +
"</ul>");
});
it("should convert basic definitions to React elements", function () {
var result = React.renderToStaticMarkup(React.createElement(TestBasicComponent, {}));
result.should.equal("<div>" +
"<h1>Foo</h1>" +
"<p>Bar</p>" +
"</div>");
});
});