Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81155 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @emails react-core
10
*/
11
12
"use strict";
13
14
// Requires
15
var React;
16
var ReactTestUtils;
17
var reactComponentExpect;
18
19
// Test components
20
var LowerLevelComposite;
21
var MyCompositeComponent;
22
23
var expectSingleChildlessDiv;
24
25
/**
26
* Integration test, testing the combination of JSX with our unit of
27
* abstraction, `ReactCompositeComponent` does not ever add superfluous DOM
28
* nodes.
29
*/
30
describe('ReactCompositeComponentDOMMinimalism', function() {
31
32
beforeEach(function() {
33
reactComponentExpect = require('reactComponentExpect');
34
React = require('React');
35
ReactTestUtils = require('ReactTestUtils');
36
37
LowerLevelComposite = React.createClass({
38
render: function() {
39
return (
40
<div>
41
{this.props.children}
42
</div>
43
);
44
}
45
});
46
47
MyCompositeComponent = React.createClass({
48
render: function() {
49
return (
50
<LowerLevelComposite>
51
{this.props.children}
52
</LowerLevelComposite>
53
);
54
}
55
});
56
57
expectSingleChildlessDiv = function(instance) {
58
reactComponentExpect(instance)
59
.expectRenderedChild()
60
.toBeCompositeComponentWithType(LowerLevelComposite)
61
.expectRenderedChild()
62
.toBeDOMComponentWithTag('div')
63
.toBeDOMComponentWithNoChildren();
64
};
65
});
66
67
it('should not render extra nodes for non-interpolated text', function() {
68
var instance = (
69
<MyCompositeComponent>
70
A string child
71
</MyCompositeComponent>
72
);
73
instance = ReactTestUtils.renderIntoDocument(instance);
74
expectSingleChildlessDiv(instance);
75
});
76
77
it('should not render extra nodes for non-interpolated text', function() {
78
var instance = (
79
<MyCompositeComponent>
80
{'Interpolated String Child'}
81
</MyCompositeComponent>
82
);
83
instance = ReactTestUtils.renderIntoDocument(instance);
84
expectSingleChildlessDiv(instance);
85
});
86
87
it('should not render extra nodes for non-interpolated text', function() {
88
var instance = (
89
<MyCompositeComponent>
90
<ul>
91
This text causes no children in ul, just innerHTML
92
</ul>
93
</MyCompositeComponent>
94
);
95
instance = ReactTestUtils.renderIntoDocument(instance);
96
reactComponentExpect(instance)
97
.expectRenderedChild()
98
.toBeCompositeComponentWithType(LowerLevelComposite)
99
.expectRenderedChild()
100
.toBeDOMComponentWithTag('div')
101
.toBeDOMComponentWithChildCount(1)
102
.expectRenderedChildAt(0)
103
.toBeDOMComponentWithTag('ul')
104
.toBeDOMComponentWithNoChildren();
105
});
106
107
});
108
109