Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81159 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
var React;
15
var ReactCSSTransitionGroup;
16
var mocks;
17
18
// Most of the real functionality is covered in other unit tests, this just
19
// makes sure we're wired up correctly.
20
describe('ReactCSSTransitionGroup', function() {
21
var container;
22
23
beforeEach(function() {
24
React = require('React');
25
ReactCSSTransitionGroup = require('ReactCSSTransitionGroup');
26
mocks = require('mocks');
27
28
container = document.createElement('div');
29
});
30
31
it('should warn after time with no transitionend', function() {
32
var a = React.render(
33
<ReactCSSTransitionGroup transitionName="yolo">
34
<span key="one" id="one" />
35
</ReactCSSTransitionGroup>,
36
container
37
);
38
expect(a.getDOMNode().childNodes.length).toBe(1);
39
40
setTimeout.mock.calls.length = 0;
41
42
React.render(
43
<ReactCSSTransitionGroup transitionName="yolo">
44
<span key="two" id="two" />
45
</ReactCSSTransitionGroup>,
46
container
47
);
48
expect(a.getDOMNode().childNodes.length).toBe(2);
49
expect(a.getDOMNode().childNodes[0].id).toBe('two');
50
expect(a.getDOMNode().childNodes[1].id).toBe('one');
51
52
console.warn = mocks.getMockFunction();
53
54
// For some reason jst is adding extra setTimeout()s and grunt test isn't,
55
// so we need to do this disgusting hack.
56
for (var i = 0 ; i < setTimeout.mock.calls.length; i++) {
57
if (setTimeout.mock.calls[i][1] === 5000) {
58
setTimeout.mock.calls[i][0]();
59
break;
60
}
61
}
62
63
expect(a.getDOMNode().childNodes.length).toBe(2);
64
expect(console.warn.mock.calls.length).toBe(1);
65
});
66
67
it('should keep both sets of DOM nodes around', function() {
68
var a = React.render(
69
<ReactCSSTransitionGroup transitionName="yolo">
70
<span key="one" id="one" />
71
</ReactCSSTransitionGroup>,
72
container
73
);
74
expect(a.getDOMNode().childNodes.length).toBe(1);
75
React.render(
76
<ReactCSSTransitionGroup transitionName="yolo">
77
<span key="two" id="two" />
78
</ReactCSSTransitionGroup>,
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
});
85
86
it('should switch transitionLeave from false to true', function() {
87
var a = React.render(
88
<ReactCSSTransitionGroup
89
transitionName="yolo"
90
transitionEnter={false}
91
transitionLeave={false}>
92
<span key="one" id="one" />
93
</ReactCSSTransitionGroup>,
94
container
95
);
96
expect(a.getDOMNode().childNodes.length).toBe(1);
97
React.render(
98
<ReactCSSTransitionGroup
99
transitionName="yolo"
100
transitionEnter={false}
101
transitionLeave={false}>
102
<span key="two" id="two" />
103
</ReactCSSTransitionGroup>,
104
container
105
);
106
expect(a.getDOMNode().childNodes.length).toBe(1);
107
React.render(
108
<ReactCSSTransitionGroup
109
transitionName="yolo"
110
transitionEnter={false}
111
transitionLeave={true}>
112
<span key="three" id="three" />
113
</ReactCSSTransitionGroup>,
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');
119
});
120
121
it('should work with no children', function() {
122
React.render(
123
<ReactCSSTransitionGroup transitionName="yolo">
124
</ReactCSSTransitionGroup>,
125
container
126
);
127
});
128
129
it('should work with a null child', function() {
130
React.render(
131
<ReactCSSTransitionGroup transitionName="yolo">
132
{[null]}
133
</ReactCSSTransitionGroup>,
134
container
135
);
136
});
137
138
it('should transition from one to null', function() {
139
var a = React.render(
140
<ReactCSSTransitionGroup transitionName="yolo">
141
<span key="one" id="one" />
142
</ReactCSSTransitionGroup>,
143
container
144
);
145
expect(a.getDOMNode().childNodes.length).toBe(1);
146
React.render(
147
<ReactCSSTransitionGroup transitionName="yolo">
148
{null}
149
</ReactCSSTransitionGroup>,
150
container
151
);
152
// (Here, we expect the original child to stick around but test that no
153
// exception is thrown)
154
expect(a.getDOMNode().childNodes.length).toBe(1);
155
expect(a.getDOMNode().childNodes[0].id).toBe('one');
156
});
157
158
it('should transition from false to one', function() {
159
var a = React.render(
160
<ReactCSSTransitionGroup transitionName="yolo">
161
{false}
162
</ReactCSSTransitionGroup>,
163
container
164
);
165
expect(a.getDOMNode().childNodes.length).toBe(0);
166
React.render(
167
<ReactCSSTransitionGroup transitionName="yolo">
168
<span key="one" id="one" />
169
</ReactCSSTransitionGroup>,
170
container
171
);
172
expect(a.getDOMNode().childNodes.length).toBe(1);
173
expect(a.getDOMNode().childNodes[0].id).toBe('one');
174
});
175
176
});
177
178