[Flare] Ensure Flare components are no-ops for TestRenderer (#16192)
Dominic Gannaway committed
Jul 24, 2019 at 11:31 UTC
7ad221126f77de71f4307758518955884dd67453
2 files changed
+26
-3
packages/react-dom/src/events/__tests__/DOMEventResponderSystem-test.internal.js
+13
@@ -12,6 +12,7 @@
12
let React;
13
let ReactFeatureFlags;
14
let ReactDOM;
15
+let ReactTestRenderer;
16
17
// FIXME: What should the public API be for setting an event's priority? Right
18
// now it's an enum but is that what we want? Hard coding this for now.
@@ -80,6 +81,18 @@ describe('DOMEventResponderSystem', () => {
81
container = null;
82
});
83
84
+ it('can mount and render correctly with the ReactTestRenderer', () => {
85
+ jest.resetModules();
86
+ ReactFeatureFlags = require('shared/ReactFeatureFlags');
87
+ ReactFeatureFlags.enableFlareAPI = true;
88
+ ReactTestRenderer = require('react-test-renderer');
89
+ const TestResponder = createEventResponder({});
90
+ const renderer = ReactTestRenderer.create(
91
+ <div responders={<TestResponder />}>Hello world</div>,
92
+ );
93
+ expect(renderer).toMatchRenderedOutput(<div>Hello world</div>);
94
+ });
95
+
96
it('the event responders should fire on click event', () => {
97
let eventResponderFiredCount = 0;
98
let eventLog = [];
packages/react-test-renderer/src/ReactTestHostConfig.js
+13
-3
@@ -140,9 +140,19 @@ export function createInstance(
140
hostContext: Object,
141
internalInstanceHandle: Object,
142
): Instance {
143
+ let propsToUse = props;
144
+ if (enableFlareAPI) {
145
+ if (props.responders != null) {
146
+ // We want to remove the "responders" prop
147
+ // as we don't want it into the test renderer instance's
148
+ // props object.
149
+ const {responders, ...otherProps} = props; // eslint-disable-line
150
+ propsToUse = otherProps;
151
+ }
152
+ }
153
return {
154
type,
145
- props,
155
+ props: propsToUse,
156
isHidden: false,
157
children: [],
158
rootContainerInstance,
@@ -288,13 +298,13 @@ export function mountResponderInstance(
298
instance: Instance,
299
rootContainerInstance: Container,
300
) {
291
- throw new Error('Not yet implemented.');
301
+ // noop
302
}
303
304
export function unmountResponderInstance(
305
responderInstance: ReactEventResponderInstance<any, any>,
306
): void {
297
- throw new Error('Not yet implemented.');
307
+ // noop
308
}
309
310
export function getFundamentalComponentInstance(fundamentalInstance): Instance {