[Flare] Ensure Flare components are no-ops for TestRenderer (#16192)

This commit is contained in:
Dominic Gannaway
2019-07-24 11:31:33 +01:00
committed by GitHub
parent 06cc996994
commit 7ad221126f
2 changed files with 26 additions and 3 deletions
@@ -12,6 +12,7 @@
let React;
let ReactFeatureFlags;
let ReactDOM;
let ReactTestRenderer;
// FIXME: What should the public API be for setting an event's priority? Right
// now it's an enum but is that what we want? Hard coding this for now.
@@ -80,6 +81,18 @@ describe('DOMEventResponderSystem', () => {
container = null;
});
it('can mount and render correctly with the ReactTestRenderer', () => {
jest.resetModules();
ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.enableFlareAPI = true;
ReactTestRenderer = require('react-test-renderer');
const TestResponder = createEventResponder({});
const renderer = ReactTestRenderer.create(
<div responders={<TestResponder />}>Hello world</div>,
);
expect(renderer).toMatchRenderedOutput(<div>Hello world</div>);
});
it('the event responders should fire on click event', () => {
let eventResponderFiredCount = 0;
let eventLog = [];
+13 -3
View File
@@ -140,9 +140,19 @@ export function createInstance(
hostContext: Object,
internalInstanceHandle: Object,
): Instance {
let propsToUse = props;
if (enableFlareAPI) {
if (props.responders != null) {
// We want to remove the "responders" prop
// as we don't want it into the test renderer instance's
// props object.
const {responders, ...otherProps} = props; // eslint-disable-line
propsToUse = otherProps;
}
}
return {
type,
props,
props: propsToUse,
isHidden: false,
children: [],
rootContainerInstance,
@@ -288,13 +298,13 @@ export function mountResponderInstance(
instance: Instance,
rootContainerInstance: Container,
) {
throw new Error('Not yet implemented.');
// noop
}
export function unmountResponderInstance(
responderInstance: ReactEventResponderInstance<any, any>,
): void {
throw new Error('Not yet implemented.');
// noop
}
export function getFundamentalComponentInstance(fundamentalInstance): Instance {