36
container = document.createElement('div');
37
});
38
39
- it('should warn after time with no transitionend', function() {
40
- var a = React.renderComponent(
41
- <ReactTransitionGroup transitionName="yolo">
42
- <span key="one" id="one" />
43
- </ReactTransitionGroup>,
44
- container
45
- );
46
- expect(a.getDOMNode().childNodes.length).toBe(1);
47
-
48
- setTimeout.mock.calls.length = 0;
49
-
50
- React.renderComponent(
51
- <ReactTransitionGroup transitionName="yolo">
52
- <span key="two" id="two" />
53
- </ReactTransitionGroup>,
54
- container
55
- );
56
- expect(a.getDOMNode().childNodes.length).toBe(2);
57
- expect(a.getDOMNode().childNodes[0].id).toBe('two');
58
- expect(a.getDOMNode().childNodes[1].id).toBe('one');
59
-
60
- console.warn = mocks.getMockFunction();
61
- setTimeout.mock.calls[2][0]();
62
-
63
- expect(a.getDOMNode().childNodes.length).toBe(2);
64
- expect(console.warn.mock.calls.length).toBe(1);
65
- });
39
67
- it('should keep both sets of DOM nodes around', function() {
68
- var a = React.renderComponent(
69
- <ReactTransitionGroup transitionName="yolo">
70
- <span key="one" id="one" />
71
- </ReactTransitionGroup>,
72
- container
73
- );
74
- expect(a.getDOMNode().childNodes.length).toBe(1);
75
- React.renderComponent(
76
- <ReactTransitionGroup transitionName="yolo">
77
- <span key="two" id="two" />
78
- </ReactTransitionGroup>,
79
- container
80
- );
81
- expect(a.getDOMNode().childNodes.length).toBe(2);
82
- expect(a.getDOMNode().childNodes[0].id).toBe('two');
83
- expect(a.getDOMNode().childNodes[1].id).toBe('one');
84
- });
40
+ it('should handle willEnter correctly', function() {
41
+ var log = [];
42
+
43
+ var Child = React.createClass({
44
+ componentDidMount: function() {
45
+ log.push('didMount');
46
+ },
47
+ componentWillEnter: function(cb) {
48
+ log.push('willEnter');
49
+ cb();
50
+ },
51
+ componentDidEnter: function() {
52
+ log.push('didEnter');
53
+ },
54
+ componentWillLeave: function(cb) {
55
+ log.push('willLeave');
56
+ cb();
57
+ },
58
+ componentDidLeave: function() {
59
+ log.push('didLeave');
60
+ },
61
+ componentWillUnmount: function() {
62
+ log.push('willUnmount');
63
+ },
64
+ render: function() {
65
+ return <span />;
66
+ }
67
+ });
68
86
- it('should switch transitionLeave from false to true', function() {
87
- var a = React.renderComponent(
88
- <ReactTransitionGroup
89
- transitionName="yolo"
90
- transitionEnter={false}
91
- transitionLeave={false}>
92
- <span key="one" id="one" />
93
- </ReactTransitionGroup>,
94
- container
95
- );
96
- expect(a.getDOMNode().childNodes.length).toBe(1);
97
- React.renderComponent(
98
- <ReactTransitionGroup
99
- transitionName="yolo"
100
- transitionEnter={false}
101
- transitionLeave={false}>
102
- <span key="two" id="two" />
103
- </ReactTransitionGroup>,
104
- container
105
- );
106
- expect(a.getDOMNode().childNodes.length).toBe(1);
107
- React.renderComponent(
108
- <ReactTransitionGroup
109
- transitionName="yolo"
110
- transitionEnter={false}
111
- transitionLeave={true}>
112
- <span key="three" id="three" />
113
- </ReactTransitionGroup>,
114
- container
115
- );
116
- expect(a.getDOMNode().childNodes.length).toBe(2);
117
- expect(a.getDOMNode().childNodes[0].id).toBe('three');
118
- expect(a.getDOMNode().childNodes[1].id).toBe('two');
69
+ var Component = React.createClass({
70
+ getInitialState: function() {
71
+ return {count: 1};
72
+ },
73
+ render: function() {
74
+ var children = [];
75
+ for (var i = 0; i < this.state.count; i++) {
76
+ children.push(<Child key={i} />);
77
+ }
78
+ return <ReactTransitionGroup>{children}</ReactTransitionGroup>;
79
+ }
80
+ });
81
+
82
+ var instance = React.renderComponent(<Component />, container);
83
+ expect(log).toEqual(['didMount']);
84
+
85
+ instance.setState({count: 2}, function() {
86
+ expect(log).toEqual(['didMount', 'didMount', 'willEnter', 'didEnter']);
87
+ instance.setState({count: 1}, function() {
88
+ expect(log).toEqual([
89
+ "didMount", "didMount", "willEnter", "didEnter",
90
+ "willLeave", "didLeave", "willUnmount"
91
+ ]);
92
+ });
93
+ });
94
});
95
121
- it('should work with no children', function () {
122
- React.renderComponent(
123
- <ReactTransitionGroup transitionName="yolo">
124
- </ReactTransitionGroup>,
125
- container
126
- );
96
+ it('should handle enter/leave/enter/leave correctly', function() {
97
+ var log = [];
98
+ var cb;
99
+
100
+ var Child = React.createClass({
101
+ componentDidMount: function() {
102
+ log.push('didMount');
103
+ },
104
+ componentWillEnter: function(_cb) {
105
+ log.push('willEnter');
106
+ cb = _cb;
107
+ },
108
+ componentDidEnter: function() {
109
+ log.push('didEnter');
110
+ },
111
+ componentWillLeave: function(cb) {
112
+ log.push('willLeave');
113
+ cb();
114
+ },
115
+ componentDidLeave: function() {
116
+ log.push('didLeave');
117
+ },
118
+ componentWillUnmount: function() {
119
+ log.push('willUnmount');
120
+ },
121
+ render: function() {
122
+ return <span />;
123
+ }
124
+ });
125
+
126
+ var Component = React.createClass({
127
+ getInitialState: function() {
128
+ return {count: 1};
129
+ },
130
+ render: function() {
131
+ var children = [];
132
+ for (var i = 0; i < this.state.count; i++) {
133
+ children.push(<Child key={i} />);
134
+ }
135
+ return <ReactTransitionGroup>{children}</ReactTransitionGroup>;
136
+ }
137
+ });
138
+
139
+ var instance = React.renderComponent(<Component />, container);
140
+ expect(log).toEqual(['didMount']);
141
+ instance.setState({count: 2});
142
+ expect(log).toEqual(['didMount', 'didMount', 'willEnter']);
143
+ for (var i = 0; i < 5; i++) {
144
+ instance.setState({count: 2});
145
+ expect(log).toEqual(['didMount', 'didMount', 'willEnter']);
146
+ instance.setState({count: 1});
147
+ }
148
+ cb();
149
+ expect(log).toEqual([
150
+ 'didMount', 'didMount', 'willEnter',
151
+ 'didEnter', 'willLeave', 'didLeave', 'willUnmount'
152
+ ]);
153
});
154
129
- it('should work with a null child', function () {
130
- React.renderComponent(
131
- <ReactTransitionGroup transitionName="yolo">
132
- {[null]}
133
- </ReactTransitionGroup>,
134
- container
135
- );
155
+ it('should handle enter/leave/enter correctly', function() {
156
+ var log = [];
157
+ var cb;
158
+
159
+ var Child = React.createClass({
160
+ componentDidMount: function() {
161
+ log.push('didMount');
162
+ },
163
+ componentWillEnter: function(_cb) {
164
+ log.push('willEnter');
165
+ cb = _cb;
166
+ },
167
+ componentDidEnter: function() {
168
+ log.push('didEnter');
169
+ },
170
+ componentWillLeave: function(cb) {
171
+ log.push('willLeave');
172
+ cb();
173
+ },
174
+ componentDidLeave: function() {
175
+ log.push('didLeave');
176
+ },
177
+ componentWillUnmount: function() {
178
+ log.push('willUnmount');
179
+ },
180
+ render: function() {
181
+ return <span />;
182
+ }
183
+ });
184
+
185
+ var Component = React.createClass({
186
+ getInitialState: function() {
187
+ return {count: 1};
188
+ },
189
+ render: function() {
190
+ var children = [];
191
+ for (var i = 0; i < this.state.count; i++) {
192
+ children.push(<Child key={i} />);
193
+ }
194
+ return <ReactTransitionGroup>{children}</ReactTransitionGroup>;
195
+ }
196
+ });
197
+
198
+ var instance = React.renderComponent(<Component />, container);
199
+ expect(log).toEqual(['didMount']);
200
+ instance.setState({count: 2});
201
+ expect(log).toEqual(['didMount', 'didMount', 'willEnter']);
202
+ for (var i = 0; i < 5; i++) {
203
+ instance.setState({count: 1});
204
+ expect(log).toEqual(['didMount', 'didMount', 'willEnter']);
205
+ instance.setState({count: 2});
206
+ }
207
+ cb();
208
+ expect(log).toEqual([
209
+ 'didMount', 'didMount', 'willEnter', 'didEnter'
210
+ ]);
211
});
212
});