Skip to content

Commit

Permalink
Accompanying change to ShallowWrapper to resolve shallowRenderer 15.5…
Browse files Browse the repository at this point in the history
… issue
  • Loading branch information
Brian Vaughn authored and ljharb committed Apr 12, 2017
1 parent a0bb9bf commit 1c932cb
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class ShallowWrapper {
this.unrendered = nodes;
this.renderer = createShallowRenderer();
withSetStateAllowed(() => {
batchedUpdates(() => {
this.batchedUpdates(() => {
this.renderer.render(nodes, options.context);
const instance = this.instance();
if (
Expand Down Expand Up @@ -142,6 +142,16 @@ class ShallowWrapper {
this.complexSelector = new ComplexSelector(buildPredicate, findWhereUnwrapped, childrenOfNode);
}

batchedUpdates(fn) {
const renderer = this.root.renderer;
if (renderer.unstable_batchedUpdates) {
// React 15.5+ exposes batching on shallow renderer itself
return renderer.unstable_batchedUpdates(fn);
}
// React <15.5: Fallback to ReactDOM
return batchedUpdates(fn);
}

/**
* Returns the wrapped ReactElement.
*
Expand Down Expand Up @@ -223,7 +233,7 @@ class ShallowWrapper {
const prevContext = instance.context;
const nextProps = props || prevProps;
const nextContext = context || prevContext;
batchedUpdates(() => {
this.batchedUpdates(() => {
let shouldRender = true;
// dirty hack:
// make sure that componentWillReceiveProps is called before shouldComponentUpdate
Expand Down Expand Up @@ -611,7 +621,7 @@ class ShallowWrapper {
withSetStateAllowed(() => {
// TODO(lmr): create/use synthetic events
// TODO(lmr): emulate React's event propagation
batchedUpdates(() => {
this.batchedUpdates(() => {
handler(...args);
});
this.root.update();
Expand Down

0 comments on commit 1c932cb

Please sign in to comment.