Skip to content

Commit

Permalink
Don't run injections in stack ReactTestRenderer factory function
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Apr 14, 2017
1 parent cc8ca86 commit d98cfee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/renderers/testing/__tests__/ReactTestRenderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ describe('ReactTestRenderer', () => {
});
});

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

Expand Down
47 changes: 30 additions & 17 deletions src/renderers/testing/stack/ReactTestRendererStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,31 @@ type ReactTestRendererJSON = {
$$typeof?: any,
};

let injected = false;
function inject() {
if (injected) {
return;
}

injected = true;

ReactUpdates.injection.injectReconcileTransaction(
ReactTestReconcileTransaction,
);
ReactUpdates.injection.injectBatchingStrategy(ReactDefaultBatchingStrategy);

ReactHostComponent.injection.injectGenericComponentClass(ReactTestComponent);
ReactHostComponent.injection.injectTextComponentClass(ReactTestTextComponent);
ReactEmptyComponent.injection.injectEmptyComponentFactory(function() {
return new ReactTestEmptyComponent();
});

ReactComponentEnvironment.injection.injectEnvironment({
processChildrenUpdates: function() {},
replaceNodeWithMarkup: function() {},
});
}

/**
* Drill down (through composites and empty components) until we get a native or
* native text component.
Expand Down Expand Up @@ -134,24 +159,12 @@ Object.assign(ReactTestComponent.prototype, ReactMultiChild);

// =============================================================================

ReactUpdates.injection.injectReconcileTransaction(
ReactTestReconcileTransaction,
);
ReactUpdates.injection.injectBatchingStrategy(ReactDefaultBatchingStrategy);

ReactHostComponent.injection.injectGenericComponentClass(ReactTestComponent);
ReactHostComponent.injection.injectTextComponentClass(ReactTestTextComponent);
ReactEmptyComponent.injection.injectEmptyComponentFactory(function() {
return new ReactTestEmptyComponent();
});

ReactComponentEnvironment.injection.injectEnvironment({
processChildrenUpdates: function() {},
replaceNodeWithMarkup: function() {},
});

var ReactTestRenderer = {
create: ReactTestMount.render,
create: () => {
inject();

return ReactTestMount.render();
},
/* eslint-disable camelcase */
unstable_batchedUpdates: ReactUpdates.batchedUpdates,
/* eslint-enable camelcase */
Expand Down

0 comments on commit d98cfee

Please sign in to comment.