react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / browser / __tests__ / ReactDOM-test.js
81155 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/*jslint evil: true */1213"use strict";1415var React = require('React');16var ReactDOM = require('ReactDOM');17var ReactMount = require('ReactMount');18var ReactTestUtils = require('ReactTestUtils');19var div = React.createFactory('div');2021describe('ReactDOM', function() {22// TODO: uncomment this test once we can run in phantom, which23// supports real submit events.24/*25it('should bubble onSubmit', function() {26var count = 0;27var form;28var Parent = React.createClass({29handleSubmit: function() {30count++;31return false;32},33render: function() {34return <Child />;35}36});37var Child = React.createClass({38render: function() {39return <form><input type="submit" value="Submit" /></form>;40},41componentDidMount: function() {42form = this.getDOMNode();43}44});45var instance = ReactTestUtils.renderIntoDocument(<Parent />);46form.submit();47expect(count).toEqual(1);48});49*/5051it("should allow children to be passed as an argument", function() {52var argDiv = ReactTestUtils.renderIntoDocument(53div(null, 'child')54);55var argNode = ReactMount.getNode(argDiv._rootNodeID);56expect(argNode.innerHTML).toBe('child');57});5859it("should overwrite props.children with children argument", function() {60var conflictDiv = ReactTestUtils.renderIntoDocument(61div({children: 'fakechild'}, 'child')62);63var conflictNode = ReactMount.getNode(conflictDiv._rootNodeID);64expect(conflictNode.innerHTML).toBe('child');65});6667/**68* We need to make sure that updates occur to the actual node that's in the69* DOM, instead of a stale cache.70*/71it("should purge the DOM cache when removing nodes", function() {72var myDiv = ReactTestUtils.renderIntoDocument(73<div>{{74theDog: <div className="dog" />,75theBird: <div className="bird" />76}}</div>77);78// Warm the cache with theDog79myDiv.setProps({80children: {81theDog: <div className="dogbeforedelete" />,82theBird: <div className="bird" />83}84});85// Remove theDog - this should purge the cache86myDiv.setProps({87children: {88theBird: <div className="bird" />89}90});91// Now, put theDog back. It's now a different DOM node.92myDiv.setProps({93children: {94theDog: <div className="dog" />,95theBird: <div className="bird" />96}97});98// Change the className of theDog. It will use the same element99myDiv.setProps({100children: {101theDog: <div className="bigdog" />,102theBird: <div className="bird" />103}104});105var root = ReactMount.getNode(myDiv._rootNodeID);106var dog = root.childNodes[0];107expect(dog.className).toBe('bigdog');108});109110it('allow React.DOM factories to be called without warnings', function() {111spyOn(console, 'warn');112var element = React.DOM.div();113expect(element.type).toBe('div');114expect(console.warn.argsForCall.length).toBe(0);115});116117it('warns but allow dom factories to be used in createFactory', function() {118spyOn(console, 'warn');119var factory = React.createFactory(React.DOM.div);120expect(factory().type).toBe('div');121expect(console.warn.argsForCall.length).toBe(1);122expect(console.warn.argsForCall[0][0]).toContain(123'Do not pass React.DOM.div'124);125});126127it('warns but allow dom factories to be used in createElement', function() {128spyOn(console, 'warn');129var element = React.createElement(React.DOM.div);130expect(element.type).toBe('div');131expect(console.warn.argsForCall.length).toBe(1);132expect(console.warn.argsForCall[0][0]).toContain(133'Do not pass React.DOM.div'134);135});136});137138139