-
Notifications
You must be signed in to change notification settings - Fork 47.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved lifecycle deprecation warnings behind (disabled) feature flag
Updated tests accordingly, by temporarily splitting tests that were specific to this feature-flag into their own, internal tests. This was the only way I knew of to interact with the feature flag without breaking our build/dist tests.
- Loading branch information
Showing
15 changed files
with
395 additions
and
244 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.internal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @emails react-core | ||
*/ | ||
|
||
'use strict'; | ||
|
||
let React; | ||
let ReactDOM; | ||
let ReactFeatureFlags; | ||
|
||
/** | ||
* TODO: We should make any setState calls fail in | ||
* `getInitialState` and `componentWillMount`. They will usually fail | ||
* anyways because `this._renderedComponent` is empty, however, if a component | ||
* is *reused*, then that won't be the case and things will appear to work in | ||
* some cases. Better to just block all updates in initialization. | ||
*/ | ||
describe('ReactComponentLifeCycle', () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
|
||
ReactFeatureFlags = require('shared/ReactFeatureFlags'); | ||
ReactFeatureFlags.warnAboutDeprecatedLifecycles = true; | ||
|
||
React = require('react'); | ||
ReactDOM = require('react-dom'); | ||
}); | ||
|
||
// TODO (RFC #6) Merge this back into ReactComponentLifeCycles-test once | ||
// the 'warnAboutDeprecatedLifecycles' feature flag has been removed. | ||
it('warns about deprecated unsafe lifecycles', function() { | ||
class MyComponent extends React.Component { | ||
componentWillMount() {} | ||
componentWillReceiveProps() {} | ||
componentWillUpdate() {} | ||
render() { | ||
return null; | ||
} | ||
} | ||
|
||
const container = document.createElement('div'); | ||
expect(() => ReactDOM.render(<MyComponent x={1} />, container)).toWarnDev([ | ||
'Warning: MyComponent: componentWillMount() is deprecated and will be ' + | ||
'removed in the next major version. ' + | ||
'Please use UNSAFE_componentWillMount() instead.', | ||
]); | ||
|
||
expect(() => ReactDOM.render(<MyComponent x={2} />, container)).toWarnDev([ | ||
'Warning: MyComponent: componentWillReceiveProps() is deprecated and ' + | ||
'will be removed in the next major version. ' + | ||
'Please use UNSAFE_componentWillReceiveProps() instead.', | ||
'Warning: MyComponent: componentWillUpdate() is deprecated and will be ' + | ||
'removed in the next major version. ' + | ||
'Please use UNSAFE_componentWillUpdate() instead.', | ||
]); | ||
|
||
// Dedupe check (instantiate and update) | ||
ReactDOM.render(<MyComponent key="new" x={1} />, container); | ||
ReactDOM.render(<MyComponent key="new" x={2} />, container); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/react-dom/src/__tests__/ReactDOMServerLifecycles-test.internal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @emails react-core | ||
*/ | ||
|
||
'use strict'; | ||
|
||
let React; | ||
let ReactFeatureFlags; | ||
let ReactDOMServer; | ||
|
||
describe('ReactDOMServerLifecycles', () => { | ||
beforeEach(() => { | ||
ReactFeatureFlags = require('shared/ReactFeatureFlags'); | ||
ReactFeatureFlags.warnAboutDeprecatedLifecycles = true; | ||
|
||
React = require('react'); | ||
ReactDOMServer = require('react-dom/server'); | ||
}); | ||
|
||
// TODO (RFC #6) Merge this back into ReactDOMServerLifecycles-test once | ||
// the 'warnAboutDeprecatedLifecycles' feature flag has been removed. | ||
it('should warn about deprecated lifecycle hooks', () => { | ||
class Component extends React.Component { | ||
componentWillMount() {} | ||
render() { | ||
return null; | ||
} | ||
} | ||
|
||
expect(() => ReactDOMServer.renderToString(<Component />)).toWarnDev( | ||
'Warning: Component: componentWillMount() is deprecated and will be removed ' + | ||
'in the next major version. Please use UNSAFE_componentWillMount() instead.', | ||
); | ||
|
||
// De-duped | ||
ReactDOMServer.renderToString(<Component />); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.