Skip to content

Commit

Permalink
Use ReactDOM.unstable_batchedUpdates in Fiber tests (facebook#8263)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored and acusti committed Mar 15, 2017
1 parent 449b7f7 commit 5a0c048
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
11 changes: 0 additions & 11 deletions scripts/fiber/tests-failing.txt
Expand Up @@ -567,20 +567,9 @@ src/renderers/shared/stack/reconciler/__tests__/ReactStatelessComponent-test.js
* should warn when using non-React functions in JSX

src/renderers/shared/stack/reconciler/__tests__/ReactUpdates-test.js
* should batch state when updating state twice
* should batch state when updating two different state keys
* should batch state and props together
* should batch parent/child state updates together
* should batch child/parent state updates together
* should support chained state updates
* should batch forceUpdate together
* should update children even if parent blocks updates
* should flow updates correctly
* should share reconcile transaction across different roots
* should queue mount-ready handlers across different roots
* should flush updates in the correct order across roots
* should queue updates from during mount
* does not call render after a component as been deleted
* marks top-level updates
* throws in setState if the update callback is not a function
* throws in replaceState if the update callback is not a function
Expand Down
11 changes: 11 additions & 0 deletions scripts/fiber/tests-passing.txt
Expand Up @@ -1155,10 +1155,21 @@ src/renderers/shared/stack/reconciler/__tests__/ReactStatelessComponent-test.js
* should allow simple functions to return false

src/renderers/shared/stack/reconciler/__tests__/ReactUpdates-test.js
* should batch state when updating state twice
* should batch state when updating two different state keys
* should batch state and props together
* should batch parent/child state updates together
* should batch child/parent state updates together
* should support chained state updates
* should batch forceUpdate together
* should update children even if parent blocks updates
* should not reconcile children passed via props
* should flow updates correctly
* should flush updates in the correct order
* should flush updates in the correct order across roots
* should queue nested updates
* calls componentWillReceiveProps setState callback properly
* does not call render after a component as been deleted
* does not update one component twice in a batch (#2410)
* does not update one component twice in a batch (#6371)
* unstable_batchedUpdates should return value from a callback
Expand Down
Expand Up @@ -19,7 +19,6 @@ var ReactCurrentOwner;
var ReactPropTypes;
var ReactServerRendering;
var ReactTestUtils;
var ReactUpdates;

describe('ReactCompositeComponent', () => {

Expand All @@ -31,7 +30,6 @@ describe('ReactCompositeComponent', () => {
ReactPropTypes = require('ReactPropTypes');
ReactTestUtils = require('ReactTestUtils');
ReactServerRendering = require('ReactServerRendering');
ReactUpdates = require('ReactUpdates');

MorphingComponent = class extends React.Component {
state = {activated: false};
Expand Down Expand Up @@ -813,7 +811,7 @@ describe('ReactCompositeComponent', () => {
expect(childInstance).toBeNull();

expect(parentInstance.state.flag).toBe(false);
ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
parentInstance.setState({flag: true});
});
expect(parentInstance.state.flag).toBe(true);
Expand Down Expand Up @@ -1209,15 +1207,15 @@ describe('ReactCompositeComponent', () => {

// When more than one state update is enqueued, we have the same behavior
var fifthState = new NotActuallyImmutable('fifth');
ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
moo.setState({str: 'fourth'});
moo.replaceState(fifthState);
});
expect(moo.state).toBe(fifthState);

// When more than one state update is enqueued, we have the same behavior
var sixthState = new NotActuallyImmutable('sixth');
ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
moo.replaceState(sixthState);
moo.setState({str: 'seventh'});
});
Expand Down
Expand Up @@ -42,7 +42,7 @@ describe('ReactUpdates', () => {
var instance = ReactTestUtils.renderIntoDocument(<Component />);
expect(instance.state.x).toBe(0);

ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
instance.setState({x: 1});
instance.setState({x: 2});
expect(instance.state.x).toBe(0);
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('ReactUpdates', () => {
expect(instance.state.x).toBe(0);
expect(instance.state.y).toBe(0);

ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
instance.setState({x: 1});
instance.setState({y: 2});
expect(instance.state.x).toBe(0);
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('ReactUpdates', () => {
expect(instance.props.x).toBe(0);
expect(instance.state.y).toBe(0);

ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
ReactDOM.render(<Component x={1} />, container);
instance.setState({y: 2});
expect(instance.props.x).toBe(0);
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('ReactUpdates', () => {
expect(instance.state.x).toBe(0);
expect(child.state.y).toBe(0);

ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
instance.setState({x: 1});
child.setState({y: 2});
expect(instance.state.x).toBe(0);
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('ReactUpdates', () => {
expect(instance.state.x).toBe(0);
expect(child.state.y).toBe(0);

ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
child.setState({y: 2});
instance.setState({x: 1});
expect(instance.state.x).toBe(0);
Expand Down Expand Up @@ -237,7 +237,7 @@ describe('ReactUpdates', () => {
expect(instance.state.x).toBe(0);

var innerCallbackRun = false;
ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
instance.setState({x: 1}, function() {
instance.setState({x: 2}, function() {
expect(this).toBe(instance);
Expand Down Expand Up @@ -281,7 +281,7 @@ describe('ReactUpdates', () => {
expect(instance.state.x).toBe(0);

var callbacksRun = 0;
ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
instance.setState({x: 1}, function() {
callbacksRun++;
});
Expand Down Expand Up @@ -330,14 +330,14 @@ describe('ReactUpdates', () => {
expect(parentRenderCount).toBe(1);
expect(childRenderCount).toBe(1);

ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
instance.setState({x: 1});
});

expect(parentRenderCount).toBe(1);
expect(childRenderCount).toBe(1);

ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
instance.refs.child.setState({x: 1});
});

Expand Down Expand Up @@ -465,7 +465,7 @@ describe('ReactUpdates', () => {
function testUpdates(components, desiredWillUpdates, desiredDidUpdates) {
var i;

ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
for (i = 0; i < components.length; i++) {
triggerUpdate(components[i]);
}
Expand All @@ -475,7 +475,7 @@ describe('ReactUpdates', () => {

// Try them in reverse order

ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
for (i = components.length - 1; i >= 0; i--) {
triggerUpdate(components[i]);
}
Expand Down Expand Up @@ -519,15 +519,15 @@ describe('ReactUpdates', () => {
var containerB = document.createElement('div');

// Initial renders aren't batched together yet...
ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
ReactDOM.render(<Component text="A1" />, containerA);
ReactDOM.render(<Component text="B1" />, containerB);
});
expect(ReconcileTransaction.getPooled.calls.count()).toBe(2);

// ...but updates are! Here only one more transaction is used, which means
// we only have to initialize and close the wrappers once.
ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
ReactDOM.render(<Component text="A2" />, containerA);
ReactDOM.render(<Component text="B2" />, containerB);
});
Expand Down Expand Up @@ -568,7 +568,7 @@ describe('ReactUpdates', () => {
a = ReactTestUtils.renderIntoDocument(<A />);
b = ReactTestUtils.renderIntoDocument(<B />);

ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
a.setState({x: 1});
b.setState({x: 1});
});
Expand Down Expand Up @@ -679,7 +679,7 @@ describe('ReactUpdates', () => {

expect(updates).toEqual([0, 1, 2]);

ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
// Simulate update on each component from top to bottom.
instances.forEach(function(instance) {
instance.forceUpdate();
Expand Down Expand Up @@ -771,7 +771,7 @@ describe('ReactUpdates', () => {
}
}

ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
ReactTestUtils.renderIntoDocument(
<div>
<A />
Expand Down Expand Up @@ -837,7 +837,7 @@ describe('ReactUpdates', () => {

var component = ReactTestUtils.renderIntoDocument(<A />);

ReactUpdates.batchedUpdates(function() {
ReactDOM.unstable_batchedUpdates(function() {
// B will have scheduled an update but the batching should ensure that its
// update never fires.
componentB.setState({updates: 1});
Expand Down

0 comments on commit 5a0c048

Please sign in to comment.