Skip to content

Commit d98cfee

Browse files
author
Brian Vaughn
committed
Don't run injections in stack ReactTestRenderer factory function
1 parent cc8ca86 commit d98cfee

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

src/renderers/testing/__tests__/ReactTestRenderer-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ describe('ReactTestRenderer', () => {
568568
});
569569
});
570570

571-
it('toTree() renders complicated trees of composites and hosts', () => {
571+
fit('toTree() renders complicated trees of composites and hosts', () => {
572572
// SFC returning host. no children props.
573573
var Qoo = () => <span className="Qoo">Hello World!</span>;
574574

src/renderers/testing/stack/ReactTestRendererStack.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,31 @@ type ReactTestRendererJSON = {
3636
$$typeof?: any,
3737
};
3838

39+
let injected = false;
40+
function inject() {
41+
if (injected) {
42+
return;
43+
}
44+
45+
injected = true;
46+
47+
ReactUpdates.injection.injectReconcileTransaction(
48+
ReactTestReconcileTransaction,
49+
);
50+
ReactUpdates.injection.injectBatchingStrategy(ReactDefaultBatchingStrategy);
51+
52+
ReactHostComponent.injection.injectGenericComponentClass(ReactTestComponent);
53+
ReactHostComponent.injection.injectTextComponentClass(ReactTestTextComponent);
54+
ReactEmptyComponent.injection.injectEmptyComponentFactory(function() {
55+
return new ReactTestEmptyComponent();
56+
});
57+
58+
ReactComponentEnvironment.injection.injectEnvironment({
59+
processChildrenUpdates: function() {},
60+
replaceNodeWithMarkup: function() {},
61+
});
62+
}
63+
3964
/**
4065
* Drill down (through composites and empty components) until we get a native or
4166
* native text component.
@@ -134,24 +159,12 @@ Object.assign(ReactTestComponent.prototype, ReactMultiChild);
134159

135160
// =============================================================================
136161

137-
ReactUpdates.injection.injectReconcileTransaction(
138-
ReactTestReconcileTransaction,
139-
);
140-
ReactUpdates.injection.injectBatchingStrategy(ReactDefaultBatchingStrategy);
141-
142-
ReactHostComponent.injection.injectGenericComponentClass(ReactTestComponent);
143-
ReactHostComponent.injection.injectTextComponentClass(ReactTestTextComponent);
144-
ReactEmptyComponent.injection.injectEmptyComponentFactory(function() {
145-
return new ReactTestEmptyComponent();
146-
});
147-
148-
ReactComponentEnvironment.injection.injectEnvironment({
149-
processChildrenUpdates: function() {},
150-
replaceNodeWithMarkup: function() {},
151-
});
152-
153162
var ReactTestRenderer = {
154-
create: ReactTestMount.render,
163+
create: () => {
164+
inject();
165+
166+
return ReactTestMount.render();
167+
},
155168
/* eslint-disable camelcase */
156169
unstable_batchedUpdates: ReactUpdates.batchedUpdates,
157170
/* eslint-enable camelcase */

0 commit comments

Comments
 (0)