react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / core / __tests__ / refs-destruction-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"use strict";1213var React = require('React');14var ReactTestUtils = require('ReactTestUtils');15var reactComponentExpect= require('reactComponentExpect');1617var TestComponent = React.createClass({18render: function() {19return (20<div>21<div ref="theInnerDiv">22Lets try to destroy this.23</div>24</div>25);26}27});2829describe('refs-destruction', function() {30beforeEach(function() {31require('mock-modules').dumpCache();32});3334it("should remove refs when destroying the parent", function() {35var testInstance = ReactTestUtils.renderIntoDocument(<TestComponent />);36reactComponentExpect(testInstance.refs.theInnerDiv)37.toBeDOMComponentWithTag('div');38expect(Object.keys(testInstance.refs || {}).length).toEqual(1);39testInstance.unmountComponent();40expect(Object.keys(testInstance.refs || {}).length).toEqual(0);41});4243it("should remove refs when destroying the child", function() {44var testInstance = ReactTestUtils.renderIntoDocument(<TestComponent />);45reactComponentExpect(testInstance.refs.theInnerDiv)46.toBeDOMComponentWithTag('div');47expect(Object.keys(testInstance.refs || {}).length).toEqual(1);48testInstance.refs.theInnerDiv.unmountComponent();49expect(Object.keys(testInstance.refs || {}).length).toEqual(0);50});51});525354