-
Notifications
You must be signed in to change notification settings - Fork 51k
Expand file tree
/
Copy pathReactEventIndependence-test.js
More file actions
67 lines (58 loc) · 1.8 KB
/
ReactEventIndependence-test.js
File metadata and controls
67 lines (58 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
*/
'use strict';
var React;
var ReactDOM;
var ReactTestUtils;
describe('ReactEventIndependence', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
ReactTestUtils = require('react-dom/test-utils');
});
it('does not crash with other react inside', () => {
var clicks = 0;
var div = ReactTestUtils.renderIntoDocument(
<div
onClick={() => clicks++}
dangerouslySetInnerHTML={{
__html: '<button data-reactid=".z">click me</div>',
}}
/>,
);
ReactTestUtils.SimulateNative.click(div.firstChild);
expect(clicks).toBe(1);
});
it('does not crash with other react outside', () => {
var clicks = 0;
var outer = document.createElement('div');
outer.setAttribute('data-reactid', '.z');
var inner = ReactDOM.render(
<button onClick={() => clicks++}>click me</button>,
outer,
);
ReactTestUtils.SimulateNative.click(inner);
expect(clicks).toBe(1);
});
it('does not when event fired on unmounted tree', () => {
var clicks = 0;
var container = document.createElement('div');
var button = ReactDOM.render(
<button onClick={() => clicks++}>click me</button>,
container,
);
// Now we unmount the component, as if caused by a non-React event handler
// for the same click we're about to simulate, like closing a layer:
ReactDOM.unmountComponentAtNode(container);
ReactTestUtils.SimulateNative.click(button);
// Since the tree is unmounted, we don't dispatch the click event.
expect(clicks).toBe(0);
});
});