Skip to content

Commit 663cd4e

Browse files
committed
Add unit test for transitionEnterTimeout and transitionLeaveTimeout
1 parent 1791abd commit 663cd4e

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

tests/index.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,38 @@ class TodoList extends Component {
5151
}
5252
}
5353

54+
class TodoListWithTimeout extends Component {
55+
state = {
56+
items: ['hello', 'world', 'click', 'me']
57+
};
58+
59+
handleAdd(item) {
60+
let { items } = this.state;
61+
items = items.concat(item);
62+
this.setState({ items });
63+
}
64+
65+
handleRemove(i) {
66+
let { items } = this.state;
67+
items.splice(i, 1);
68+
this.setState({ items });
69+
}
70+
71+
render(_, { items }) {
72+
return (
73+
<div>
74+
<CSSTransitionGroup transitionName="example" transitionEnterTimeout={500} transitionLeaveTimeout={200}>
75+
{ items.map( (item, i) => (
76+
<Todo key={item} onClick={this.handleRemove.bind(this, i)}>
77+
{item}
78+
</Todo>
79+
)) }
80+
</CSSTransitionGroup>
81+
</div>
82+
);
83+
}
84+
}
85+
5486
class SVGList extends Component {
5587
state = {
5688
items: ['hello', 'world', 'click', 'me']
@@ -182,6 +214,67 @@ describe('CSSTransitionGroup', () => {
182214
});
183215
});
184216

217+
describe('CSSTransitionGroup: timeout', () => {
218+
let container = document.createElement('div'),
219+
list, root;
220+
document.body.appendChild(container);
221+
222+
let $ = s => [].slice.call(container.querySelectorAll(s));
223+
224+
beforeEach( () => {
225+
root = render(<div><Nothing /></div>, container, root);
226+
root = render(<div><TodoListWithTimeout ref={c => list=c} /></div>, container, root);
227+
});
228+
229+
afterEach( () => {
230+
list = null;
231+
});
232+
233+
it('create works', () => {
234+
expect($('.item')).to.have.length(4);
235+
});
236+
237+
it('transitionLeave works with the transitionLeaveTimeout', done => {
238+
// this.timeout(5999);
239+
list.handleRemove(0);
240+
241+
// make sure -leave class was added
242+
setTimeout( () => {
243+
expect($('.item')).to.have.length(4);
244+
245+
expect($('.item')[0].className).to.contain('example-leave');
246+
expect($('.item')[0].className).to.contain('example-leave-active');
247+
}, 100);
248+
249+
// then make sure it's gone
250+
setTimeout( () => {
251+
expect($('.item')).to.have.length(3);
252+
done();
253+
}, 300);
254+
});
255+
256+
it('transitionEnter works with the transitionEnterTimeout', done => {
257+
// this.timeout(5999);
258+
list.handleAdd(Date.now());
259+
260+
setTimeout( () => {
261+
expect($('.item')).to.have.length(5);
262+
263+
expect($('.item')[4].className).to.contain('example-enter');
264+
expect($('.item')[4].className).to.contain('example-enter-active');
265+
}, 300);
266+
267+
setTimeout( () => {
268+
expect($('.item')).to.have.length(5);
269+
270+
expect($('.item')[4].className).not.to.contain('example-enter');
271+
expect($('.item')[4].className).not.to.contain('example-enter-active');
272+
273+
done();
274+
}, 600);
275+
});
276+
});
277+
185278
describe('CSSTransitionGroup: SVG', () => {
186279
let container = document.createElement('div'),
187280
list, root;

0 commit comments

Comments
 (0)