Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81159 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
16
describe('ReactMount', function() {
17
it("should destroy a react root upon request", function() {
18
var mainContainerDiv = document.createElement('div');
19
document.documentElement.appendChild(mainContainerDiv);
20
21
var instanceOne = (
22
<div className="firstReactDiv">
23
</div>
24
);
25
var firstRootDiv = document.createElement('div');
26
mainContainerDiv.appendChild(firstRootDiv);
27
React.render(instanceOne, firstRootDiv);
28
29
var instanceTwo = (
30
<div className="secondReactDiv">
31
</div>
32
);
33
var secondRootDiv = document.createElement('div');
34
mainContainerDiv.appendChild(secondRootDiv);
35
React.render(instanceTwo, secondRootDiv);
36
37
// Test that two react roots are rendered in isolation
38
expect(firstRootDiv.firstChild.className).toBe('firstReactDiv');
39
expect(secondRootDiv.firstChild.className).toBe('secondReactDiv');
40
41
// Test that after unmounting each, they are no longer in the document.
42
React.unmountComponentAtNode(firstRootDiv);
43
expect(firstRootDiv.firstChild).toBeNull();
44
React.unmountComponentAtNode(secondRootDiv);
45
expect(secondRootDiv.firstChild).toBeNull();
46
});
47
});
48
49