Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81155 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @emails react-core
10
*/
11
12
"use strict";
13
14
var React = require('React');
15
var ReactTestUtils = require('ReactTestUtils');
16
var reactComponentExpect= require('reactComponentExpect');
17
18
var TestComponent = React.createClass({
19
render: function() {
20
return (
21
<div>
22
<div ref="theInnerDiv">
23
Lets try to destroy this.
24
</div>
25
</div>
26
);
27
}
28
});
29
30
describe('refs-destruction', function() {
31
beforeEach(function() {
32
require('mock-modules').dumpCache();
33
});
34
35
it("should remove refs when destroying the parent", function() {
36
var testInstance = ReactTestUtils.renderIntoDocument(<TestComponent />);
37
reactComponentExpect(testInstance.refs.theInnerDiv)
38
.toBeDOMComponentWithTag('div');
39
expect(Object.keys(testInstance.refs || {}).length).toEqual(1);
40
testInstance.unmountComponent();
41
expect(Object.keys(testInstance.refs || {}).length).toEqual(0);
42
});
43
44
it("should remove refs when destroying the child", function() {
45
var testInstance = ReactTestUtils.renderIntoDocument(<TestComponent />);
46
reactComponentExpect(testInstance.refs.theInnerDiv)
47
.toBeDOMComponentWithTag('div');
48
expect(Object.keys(testInstance.refs || {}).length).toEqual(1);
49
testInstance.refs.theInnerDiv.unmountComponent();
50
expect(Object.keys(testInstance.refs || {}).length).toEqual(0);
51
});
52
});
53
54