246
test(<Foo update={true} />, 'DIV', 'updated');
247
});
248
249
- it('renders based on context in the constructor', () => {
250
- class Foo extends React.Component {
251
- constructor(props, context) {
252
- super(props, context);
253
- this.state = {tag: context.tag, className: this.context.className};
254
- }
255
- render() {
256
- const Tag = this.state.tag;
257
- return <Tag className={this.state.className} />;
249
+ if (!require('shared/ReactFeatureFlags').disableLegacyContext) {
250
+ it('renders based on context in the constructor', () => {
251
+ class Foo extends React.Component {
252
+ constructor(props, context) {
253
+ super(props, context);
254
+ this.state = {tag: context.tag, className: this.context.className};
255
+ }
256
+ render() {
257
+ const Tag = this.state.tag;
258
+ return <Tag className={this.state.className} />;
259
+ }
260
}
259
- }
260
- Foo.contextTypes = {
261
- tag: PropTypes.string,
262
- className: PropTypes.string,
263
- };
261
+ Foo.contextTypes = {
262
+ tag: PropTypes.string,
263
+ className: PropTypes.string,
264
+ };
265
265
- class Outer extends React.Component {
266
- getChildContext() {
267
- return {tag: 'span', className: 'foo'};
268
- }
269
- render() {
270
- return <Foo />;
266
+ class Outer extends React.Component {
267
+ getChildContext() {
268
+ return {tag: 'span', className: 'foo'};
269
+ }
270
+ render() {
271
+ return <Foo />;
272
+ }
273
}
272
- }
273
- Outer.childContextTypes = {
274
- tag: PropTypes.string,
275
- className: PropTypes.string,
276
- };
277
- test(<Outer />, 'SPAN', 'foo');
278
- });
274
+ Outer.childContextTypes = {
275
+ tag: PropTypes.string,
276
+ className: PropTypes.string,
277
+ };
278
+ test(<Outer />, 'SPAN', 'foo');
279
+ });
280
+ }
281
282
it('renders only once when setting state in componentWillMount', () => {
283
let renderCount = 0;
441
expect(lifeCycles).toEqual(['will-unmount']);
442
});
443
442
- it('warns when classic properties are defined on the instance, but does not invoke them.', () => {
443
- let getDefaultPropsWasCalled = false;
444
- let getInitialStateWasCalled = false;
445
- class Foo extends React.Component {
446
- constructor() {
447
- super();
448
- this.contextTypes = {};
449
- this.contextType = {};
450
- this.propTypes = {};
451
- }
452
- getInitialState() {
453
- getInitialStateWasCalled = true;
454
- return {};
455
- }
456
- getDefaultProps() {
457
- getDefaultPropsWasCalled = true;
458
- return {};
459
- }
460
- render() {
461
- return <span className="foo" />;
444
+ if (!require('shared/ReactFeatureFlags').disableLegacyContext) {
445
+ it('warns when classic properties are defined on the instance, but does not invoke them.', () => {
446
+ let getDefaultPropsWasCalled = false;
447
+ let getInitialStateWasCalled = false;
448
+ class Foo extends React.Component {
449
+ constructor() {
450
+ super();
451
+ this.contextTypes = {};
452
+ this.contextType = {};
453
+ this.propTypes = {};
454
+ }
455
+ getInitialState() {
456
+ getInitialStateWasCalled = true;
457
+ return {};
458
+ }
459
+ getDefaultProps() {
460
+ getDefaultPropsWasCalled = true;
461
+ return {};
462
+ }
463
+ render() {
464
+ return <span className="foo" />;
465
+ }
466
}
463
- }
467
465
- expect(() => test(<Foo />, 'SPAN', 'foo')).toErrorDev([
466
- 'getInitialState was defined on Foo, a plain JavaScript class.',
467
- 'getDefaultProps was defined on Foo, a plain JavaScript class.',
468
- 'propTypes was defined as an instance property on Foo.',
469
- 'contextType was defined as an instance property on Foo.',
470
- 'contextTypes was defined as an instance property on Foo.',
471
- ]);
472
- expect(getInitialStateWasCalled).toBe(false);
473
- expect(getDefaultPropsWasCalled).toBe(false);
474
- });
468
+ expect(() => test(<Foo />, 'SPAN', 'foo')).toErrorDev([
469
+ 'getInitialState was defined on Foo, a plain JavaScript class.',
470
+ 'getDefaultProps was defined on Foo, a plain JavaScript class.',
471
+ 'propTypes was defined as an instance property on Foo.',
472
+ 'contextType was defined as an instance property on Foo.',
473
+ 'contextTypes was defined as an instance property on Foo.',
474
+ ]);
475
+ expect(getInitialStateWasCalled).toBe(false);
476
+ expect(getDefaultPropsWasCalled).toBe(false);
477
+ });
478
+ }
479
480
it('does not warn about getInitialState() on class components if state is also defined.', () => {
481
class Foo extends React.Component {
557
);
558
});
559
556
- it('supports this.context passed via getChildContext', () => {
557
- class Bar extends React.Component {
558
- render() {
559
- return <div className={this.context.bar} />;
560
- }
561
- }
562
- Bar.contextTypes = {bar: PropTypes.string};
563
- class Foo extends React.Component {
564
- getChildContext() {
565
- return {bar: 'bar-through-context'};
560
+ if (!require('shared/ReactFeatureFlags').disableLegacyContext) {
561
+ it('supports this.context passed via getChildContext', () => {
562
+ class Bar extends React.Component {
563
+ render() {
564
+ return <div className={this.context.bar} />;
565
+ }
566
}
567
- render() {
568
- return <Bar />;
567
+ Bar.contextTypes = {bar: PropTypes.string};
568
+ class Foo extends React.Component {
569
+ getChildContext() {
570
+ return {bar: 'bar-through-context'};
571
+ }
572
+ render() {
573
+ return <Bar />;
574
+ }
575
}
570
- }
571
- Foo.childContextTypes = {bar: PropTypes.string};
572
- test(<Foo />, 'DIV', 'bar-through-context');
573
- });
576
+ Foo.childContextTypes = {bar: PropTypes.string};
577
+ test(<Foo />, 'DIV', 'bar-through-context');
578
+ });
579
+ }
580
581
it('supports string refs', () => {
582
class Foo extends React.Component {