react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / addons / transitions / __tests__ / ReactTransitionGroup-test.js
81159 views/**1* Copyright 2013-2014, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under the BSD-style license found in the5* LICENSE file in the root directory of this source tree. An additional grant6* of patent rights can be found in the PATENTS file in the same directory.7*8* @emails react-core9*/1011"use strict";1213var React;14var ReactTransitionGroup;15var mocks;1617// Most of the real functionality is covered in other unit tests, this just18// makes sure we're wired up correctly.19describe('ReactTransitionGroup', function() {20var container;2122beforeEach(function() {23React = require('React');24ReactTransitionGroup = require('ReactTransitionGroup');25mocks = require('mocks');2627container = document.createElement('div');28});293031it('should handle willEnter correctly', function() {32var log = [];3334var Child = React.createClass({35componentDidMount: function() {36log.push('didMount');37},38componentWillEnter: function(cb) {39log.push('willEnter');40cb();41},42componentDidEnter: function() {43log.push('didEnter');44},45componentWillLeave: function(cb) {46log.push('willLeave');47cb();48},49componentDidLeave: function() {50log.push('didLeave');51},52componentWillUnmount: function() {53log.push('willUnmount');54},55render: function() {56return <span />;57}58});5960var Component = React.createClass({61getInitialState: function() {62return {count: 1};63},64render: function() {65var children = [];66for (var i = 0; i < this.state.count; i++) {67children.push(<Child key={i} />);68}69return <ReactTransitionGroup>{children}</ReactTransitionGroup>;70}71});7273var instance = React.render(<Component />, container);74expect(log).toEqual(['didMount']);7576instance.setState({count: 2}, function() {77expect(log).toEqual(['didMount', 'didMount', 'willEnter', 'didEnter']);78instance.setState({count: 1}, function() {79expect(log).toEqual([80"didMount", "didMount", "willEnter", "didEnter",81"willLeave", "didLeave", "willUnmount"82]);83});84});85});8687it('should handle enter/leave/enter/leave correctly', function() {88var log = [];89var cb;9091var Child = React.createClass({92componentDidMount: function() {93log.push('didMount');94},95componentWillEnter: function(_cb) {96log.push('willEnter');97cb = _cb;98},99componentDidEnter: function() {100log.push('didEnter');101},102componentWillLeave: function(cb) {103log.push('willLeave');104cb();105},106componentDidLeave: function() {107log.push('didLeave');108},109componentWillUnmount: function() {110log.push('willUnmount');111},112render: function() {113return <span />;114}115});116117var Component = React.createClass({118getInitialState: function() {119return {count: 1};120},121render: function() {122var children = [];123for (var i = 0; i < this.state.count; i++) {124children.push(<Child key={i} />);125}126return <ReactTransitionGroup>{children}</ReactTransitionGroup>;127}128});129130var instance = React.render(<Component />, container);131expect(log).toEqual(['didMount']);132instance.setState({count: 2});133expect(log).toEqual(['didMount', 'didMount', 'willEnter']);134for (var i = 0; i < 5; i++) {135instance.setState({count: 2});136expect(log).toEqual(['didMount', 'didMount', 'willEnter']);137instance.setState({count: 1});138}139cb();140expect(log).toEqual([141'didMount', 'didMount', 'willEnter',142'didEnter', 'willLeave', 'didLeave', 'willUnmount'143]);144});145146it('should handle enter/leave/enter correctly', function() {147var log = [];148var cb;149150var Child = React.createClass({151componentDidMount: function() {152log.push('didMount');153},154componentWillEnter: function(_cb) {155log.push('willEnter');156cb = _cb;157},158componentDidEnter: function() {159log.push('didEnter');160},161componentWillLeave: function(cb) {162log.push('willLeave');163cb();164},165componentDidLeave: function() {166log.push('didLeave');167},168componentWillUnmount: function() {169log.push('willUnmount');170},171render: function() {172return <span />;173}174});175176var Component = React.createClass({177getInitialState: function() {178return {count: 1};179},180render: function() {181var children = [];182for (var i = 0; i < this.state.count; i++) {183children.push(<Child key={i} />);184}185return <ReactTransitionGroup>{children}</ReactTransitionGroup>;186}187});188189var instance = React.render(<Component />, container);190expect(log).toEqual(['didMount']);191instance.setState({count: 2});192expect(log).toEqual(['didMount', 'didMount', 'willEnter']);193for (var i = 0; i < 5; i++) {194instance.setState({count: 1});195expect(log).toEqual(['didMount', 'didMount', 'willEnter']);196instance.setState({count: 2});197}198cb();199expect(log).toEqual([200'didMount', 'didMount', 'willEnter', 'didEnter'201]);202});203});204205206