@samitouri / QOS-React / commits / 3766a014ae

Add media events back to TestUtils.Simulate (#12010)

The TestUtils lost media events when they were pulled out of the topLevelTypes constant. This commit adds them back by concatenating the media event keys to the list of top level types.

Nathan Hunzaker committed Jan 11, 2018 at 21:02 UTC 3766a014ae7752be70ca12b287637d8960dee6c3
3 files changed +167 -2
packages/react-dom/src/__tests__/ReactTestUtils-test.js
+8
@@ -35,6 +35,14 @@ describe('ReactTestUtils', () => {
35 ReactTestUtils = require('react-dom/test-utils');
36 });
37
38 + it('Simulate should have locally attached media events', () => {
39 + expect(Object.keys(ReactTestUtils.Simulate).sort()).toMatchSnapshot();
40 + });
41 +
42 + it('SimulateNative should have locally attached media events', () => {
43 + expect(Object.keys(ReactTestUtils.SimulateNative).sort()).toMatchSnapshot();
44 + });
45 +
46 it('gives Jest mocks a passthrough implementation with mockComponent()', () => {
47 class MockedComponent extends React.Component {
48 render() {
packages/react-dom/src/__tests__/__snapshots__/ReactTestUtils-test.js.snap new
+152
@@ -0,0 +1,152 @@
1 +// Jest Snapshot v1, https://goo.gl/fbAQLP
2 +
3 +exports[`ReactTestUtils Simulate should have locally attached media events 1`] = `
4 +Array [
5 + "abort",
6 + "animationEnd",
7 + "animationIteration",
8 + "animationStart",
9 + "beforeInput",
10 + "blur",
11 + "canPlay",
12 + "canPlayThrough",
13 + "cancel",
14 + "change",
15 + "click",
16 + "close",
17 + "compositionEnd",
18 + "compositionStart",
19 + "compositionUpdate",
20 + "contextMenu",
21 + "copy",
22 + "cut",
23 + "doubleClick",
24 + "drag",
25 + "dragEnd",
26 + "dragEnter",
27 + "dragExit",
28 + "dragLeave",
29 + "dragOver",
30 + "dragStart",
31 + "drop",
32 + "durationChange",
33 + "emptied",
34 + "encrypted",
35 + "ended",
36 + "error",
37 + "focus",
38 + "input",
39 + "invalid",
40 + "keyDown",
41 + "keyPress",
42 + "keyUp",
43 + "load",
44 + "loadStart",
45 + "loadedData",
46 + "loadedMetadata",
47 + "mouseDown",
48 + "mouseEnter",
49 + "mouseLeave",
50 + "mouseMove",
51 + "mouseOut",
52 + "mouseOver",
53 + "mouseUp",
54 + "paste",
55 + "pause",
56 + "play",
57 + "playing",
58 + "progress",
59 + "rateChange",
60 + "reset",
61 + "scroll",
62 + "seeked",
63 + "seeking",
64 + "select",
65 + "stalled",
66 + "submit",
67 + "suspend",
68 + "timeUpdate",
69 + "toggle",
70 + "touchCancel",
71 + "touchEnd",
72 + "touchMove",
73 + "touchStart",
74 + "transitionEnd",
75 + "volumeChange",
76 + "waiting",
77 + "wheel",
78 +]
79 +`;
80 +
81 +exports[`ReactTestUtils SimulateNative should have locally attached media events 1`] = `
82 +Array [
83 + "abort",
84 + "animationEnd",
85 + "animationIteration",
86 + "animationStart",
87 + "blur",
88 + "canPlay",
89 + "canPlayThrough",
90 + "cancel",
91 + "change",
92 + "click",
93 + "close",
94 + "compositionEnd",
95 + "compositionStart",
96 + "compositionUpdate",
97 + "contextMenu",
98 + "copy",
99 + "cut",
100 + "doubleClick",
101 + "drag",
102 + "dragEnd",
103 + "dragEnter",
104 + "dragExit",
105 + "dragLeave",
106 + "dragOver",
107 + "dragStart",
108 + "drop",
109 + "durationChange",
110 + "emptied",
111 + "encrypted",
112 + "ended",
113 + "error",
114 + "focus",
115 + "input",
116 + "keyDown",
117 + "keyPress",
118 + "keyUp",
119 + "load",
120 + "loadStart",
121 + "loadedData",
122 + "loadedMetadata",
123 + "mouseDown",
124 + "mouseMove",
125 + "mouseOut",
126 + "mouseOver",
127 + "mouseUp",
128 + "paste",
129 + "pause",
130 + "play",
131 + "playing",
132 + "progress",
133 + "rateChange",
134 + "scroll",
135 + "seeked",
136 + "seeking",
137 + "selectionChange",
138 + "stalled",
139 + "suspend",
140 + "textInput",
141 + "timeUpdate",
142 + "toggle",
143 + "touchCancel",
144 + "touchEnd",
145 + "touchMove",
146 + "touchStart",
147 + "transitionEnd",
148 + "volumeChange",
149 + "waiting",
150 + "wheel",
151 +]
152 +`;
packages/react-dom/src/test-utils/ReactTestUtils.js
+7 -2
@@ -18,7 +18,7 @@ import {
18 import SyntheticEvent from 'events/SyntheticEvent';
19 import invariant from 'fbjs/lib/invariant';
20
21 -import {topLevelTypes} from '../events/BrowserEventConstants';
21 +import {topLevelTypes, mediaEventTypes} from '../events/BrowserEventConstants';
22
23 const {findDOMNode} = ReactDOM;
24 const {
@@ -456,7 +456,12 @@ function makeNativeSimulator(eventType) {
456 };
457 }
458
459 -Object.keys(topLevelTypes).forEach(function(eventType) {
459 +const eventKeys = [].concat(
460 + Object.keys(topLevelTypes),
461 + Object.keys(mediaEventTypes),
462 +);
463 +
464 +eventKeys.forEach(function(eventType) {
465 // Event type is stored as 'topClick' - we transform that to 'click'
466 const convenienceName =
467 eventType.indexOf('top') === 0