react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / addons / transitions / __tests__ / ReactCSSTransitionGroup-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 ReactCSSTransitionGroup;15var mocks;1617// Most of the real functionality is covered in other unit tests, this just18// makes sure we're wired up correctly.19describe('ReactCSSTransitionGroup', function() {20var container;2122beforeEach(function() {23React = require('React');24ReactCSSTransitionGroup = require('ReactCSSTransitionGroup');25mocks = require('mocks');2627container = document.createElement('div');28});2930it('should warn after time with no transitionend', function() {31var a = React.render(32<ReactCSSTransitionGroup transitionName="yolo">33<span key="one" id="one" />34</ReactCSSTransitionGroup>,35container36);37expect(a.getDOMNode().childNodes.length).toBe(1);3839setTimeout.mock.calls.length = 0;4041React.render(42<ReactCSSTransitionGroup transitionName="yolo">43<span key="two" id="two" />44</ReactCSSTransitionGroup>,45container46);47expect(a.getDOMNode().childNodes.length).toBe(2);48expect(a.getDOMNode().childNodes[0].id).toBe('two');49expect(a.getDOMNode().childNodes[1].id).toBe('one');5051console.warn = mocks.getMockFunction();5253// For some reason jst is adding extra setTimeout()s and grunt test isn't,54// so we need to do this disgusting hack.55for (var i = 0 ; i < setTimeout.mock.calls.length; i++) {56if (setTimeout.mock.calls[i][1] === 5000) {57setTimeout.mock.calls[i][0]();58break;59}60}6162expect(a.getDOMNode().childNodes.length).toBe(2);63expect(console.warn.mock.calls.length).toBe(1);64});6566it('should keep both sets of DOM nodes around', function() {67var a = React.render(68<ReactCSSTransitionGroup transitionName="yolo">69<span key="one" id="one" />70</ReactCSSTransitionGroup>,71container72);73expect(a.getDOMNode().childNodes.length).toBe(1);74React.render(75<ReactCSSTransitionGroup transitionName="yolo">76<span key="two" id="two" />77</ReactCSSTransitionGroup>,78container79);80expect(a.getDOMNode().childNodes.length).toBe(2);81expect(a.getDOMNode().childNodes[0].id).toBe('two');82expect(a.getDOMNode().childNodes[1].id).toBe('one');83});8485it('should switch transitionLeave from false to true', function() {86var a = React.render(87<ReactCSSTransitionGroup88transitionName="yolo"89transitionEnter={false}90transitionLeave={false}>91<span key="one" id="one" />92</ReactCSSTransitionGroup>,93container94);95expect(a.getDOMNode().childNodes.length).toBe(1);96React.render(97<ReactCSSTransitionGroup98transitionName="yolo"99transitionEnter={false}100transitionLeave={false}>101<span key="two" id="two" />102</ReactCSSTransitionGroup>,103container104);105expect(a.getDOMNode().childNodes.length).toBe(1);106React.render(107<ReactCSSTransitionGroup108transitionName="yolo"109transitionEnter={false}110transitionLeave={true}>111<span key="three" id="three" />112</ReactCSSTransitionGroup>,113container114);115expect(a.getDOMNode().childNodes.length).toBe(2);116expect(a.getDOMNode().childNodes[0].id).toBe('three');117expect(a.getDOMNode().childNodes[1].id).toBe('two');118});119120it('should work with no children', function() {121React.render(122<ReactCSSTransitionGroup transitionName="yolo">123</ReactCSSTransitionGroup>,124container125);126});127128it('should work with a null child', function() {129React.render(130<ReactCSSTransitionGroup transitionName="yolo">131{[null]}132</ReactCSSTransitionGroup>,133container134);135});136137it('should transition from one to null', function() {138var a = React.render(139<ReactCSSTransitionGroup transitionName="yolo">140<span key="one" id="one" />141</ReactCSSTransitionGroup>,142container143);144expect(a.getDOMNode().childNodes.length).toBe(1);145React.render(146<ReactCSSTransitionGroup transitionName="yolo">147{null}148</ReactCSSTransitionGroup>,149container150);151// (Here, we expect the original child to stick around but test that no152// exception is thrown)153expect(a.getDOMNode().childNodes.length).toBe(1);154expect(a.getDOMNode().childNodes[0].id).toBe('one');155});156157it('should transition from false to one', function() {158var a = React.render(159<ReactCSSTransitionGroup transitionName="yolo">160{false}161</ReactCSSTransitionGroup>,162container163);164expect(a.getDOMNode().childNodes.length).toBe(0);165React.render(166<ReactCSSTransitionGroup transitionName="yolo">167<span key="one" id="one" />168</ReactCSSTransitionGroup>,169container170);171expect(a.getDOMNode().childNodes.length).toBe(1);172expect(a.getDOMNode().childNodes[0].id).toBe('one');173});174175});176177178