Skip to content

Commit bec0f73

Browse files
authored
Wrap fiber-only test in feature flag (#9665)
**what is the change?:** A test was added for a change to Fiber's behavior in #9608, and because of a bug in our CirclCI script it landed when failing for non-fiber runs of the tests. This just wraps the test in a feature flag because it seems clear it was only intended to test the new fiber behavior. Thanks to @gaearon for pairing on this! :) **why make this change?:** So that tests are passing on master. **test plan:** `npm run test ReactCompositeComponentState` **issue:** None - figured it out before anyone opened an issue afaik.
1 parent cc2450b commit bec0f73

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

src/renderers/__tests__/ReactCompositeComponentState-test.js

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
var React;
1515
var ReactDOM;
16-
var ReactDOMFeatureFlags;
16+
var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
1717

1818
var TestComponent;
1919

@@ -22,7 +22,6 @@ describe('ReactCompositeComponent-state', () => {
2222
React = require('react');
2323

2424
ReactDOM = require('react-dom');
25-
ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
2625

2726
TestComponent = class extends React.Component {
2827
constructor(props) {
@@ -448,43 +447,45 @@ describe('ReactCompositeComponent-state', () => {
448447
);
449448
});
450449

451-
it('should treat assigning to this.state inside cWM as a replaceState, with a warning', () => {
452-
spyOn(console, 'error');
453-
454-
let ops = [];
455-
class Test extends React.Component {
456-
state = {step: 1, extra: true};
457-
componentWillMount() {
458-
this.setState({step: 2}, () => {
459-
// Tests that earlier setState callbacks are not dropped
450+
if (ReactDOMFeatureFlags.useFiber) {
451+
it('should treat assigning to this.state inside cWM as a replaceState, with a warning', () => {
452+
spyOn(console, 'error');
453+
454+
let ops = [];
455+
class Test extends React.Component {
456+
state = {step: 1, extra: true};
457+
componentWillMount() {
458+
this.setState({step: 2}, () => {
459+
// Tests that earlier setState callbacks are not dropped
460+
ops.push(
461+
`callback -- step: ${this.state.step}, extra: ${!!this.state.extra}`,
462+
);
463+
});
464+
// Treat like replaceState
465+
this.state = {step: 3};
466+
}
467+
render() {
460468
ops.push(
461-
`callback -- step: ${this.state.step}, extra: ${!!this.state.extra}`,
469+
`render -- step: ${this.state.step}, extra: ${!!this.state.extra}`,
462470
);
463-
});
464-
// Treat like replaceState
465-
this.state = {step: 3};
466-
}
467-
render() {
468-
ops.push(
469-
`render -- step: ${this.state.step}, extra: ${!!this.state.extra}`,
470-
);
471-
return null;
471+
return null;
472+
}
472473
}
473-
}
474474

475-
// Mount
476-
const container = document.createElement('div');
477-
ReactDOM.render(<Test />, container);
478-
479-
expect(ops).toEqual([
480-
'render -- step: 3, extra: false',
481-
'callback -- step: 3, extra: false',
482-
]);
483-
expect(console.error.calls.count()).toEqual(1);
484-
expect(console.error.calls.argsFor(0)[0]).toEqual(
485-
'Warning: Test.componentWillMount(): Assigning directly to ' +
486-
"this.state is deprecated (except inside a component's constructor). " +
487-
'Use setState instead.',
488-
);
489-
});
475+
// Mount
476+
const container = document.createElement('div');
477+
ReactDOM.render(<Test />, container);
478+
479+
expect(ops).toEqual([
480+
'render -- step: 3, extra: false',
481+
'callback -- step: 3, extra: false',
482+
]);
483+
expect(console.error.calls.count()).toEqual(1);
484+
expect(console.error.calls.argsFor(0)[0]).toEqual(
485+
'Warning: Test.componentWillMount(): Assigning directly to ' +
486+
"this.state is deprecated (except inside a component's constructor). " +
487+
'Use setState instead.',
488+
);
489+
});
490+
}
490491
});

0 commit comments

Comments
 (0)