@samitouri / QOS-React-2 / commits / bec0f736df

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.

Flarnie Marchan committed May 11, 2017 at 13:32 UTC bec0f736df8defaf9b720619e0934c8d61515f47
1 file changed +38 -37
src/renderers/__tests__/ReactCompositeComponentState-test.js
+38 -37
@@ -13,7 +13,7 @@
13
14 var React;
15 var ReactDOM;
16 -var ReactDOMFeatureFlags;
16 +var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
17
18 var TestComponent;
19
@@ -22,7 +22,6 @@ describe('ReactCompositeComponent-state', () => {
22 React = require('react');
23
24 ReactDOM = require('react-dom');
25 - ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
25
26 TestComponent = class extends React.Component {
27 constructor(props) {
@@ -448,43 +447,45 @@ describe('ReactCompositeComponent-state', () => {
447 );
448 });
449
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() {
468 ops.push(
461 - `callback -- step: ${this.state.step}, extra: ${!!this.state.extra}`,
469 + `render -- step: ${this.state.step}, extra: ${!!this.state.extra}`,
470 );
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 + }
473 }
473 - }
474
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 + }
491 });