forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createReactClassIntegration-test.internal.js
94 lines (82 loc) · 3.66 KB
/
createReactClassIntegration-test.internal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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';
describe('create-react-class-integration', () => {
describe('ReactNative NativeMethodsMixin', () => {
let React;
let ReactNative;
let NativeMethodsMixin;
let createReactClass;
beforeEach(() => {
jest.resetModules();
React = require('react');
createReactClass = require('create-react-class/factory')(
React.Component,
React.isValidElement,
new React.Component().updater,
);
ReactNative = require('react-native-renderer');
NativeMethodsMixin =
ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
.NativeMethodsMixin;
});
it('should not warn about default DEV-only legacy lifecycle methods', () => {
const View = createReactClass({
mixins: [NativeMethodsMixin],
render: () => null,
});
ReactNative.render(<View />, 1);
});
it('should warn if users specify their own legacy componentWillMount', () => {
const View = createReactClass({
displayName: 'MyNativeComponent',
mixins: [NativeMethodsMixin],
componentWillMount: () => {},
render: () => null,
});
expect(() => ReactNative.render(<View />, 1)).toLowPriorityWarnDev(
'componentWillMount has been renamed to UNSAFE_componentWillMount, ' +
"and the old name won't work in the next major version of React.\n\n" +
'We suggest doing one of the following:\n' +
'- If you initialize state in componentWillMount, move this logic into the constructor.\n' +
'- If you fetch data or perform other side effects in componentWillMount, ' +
'move this logic into componentDidMount.\n' +
'- To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles <path/to/code>` in your project folder. ' +
'(Note that the warning will still be logged in strict mode.)\n' +
'\nPlease update the following components: MyNativeComponent\n',
{withoutStack: true},
);
});
it('should warn if users specify their own legacy componentWillReceiveProps', () => {
const View = createReactClass({
displayName: 'MyNativeComponent',
mixins: [NativeMethodsMixin],
componentWillReceiveProps: () => {},
render: () => null,
});
expect(() => ReactNative.render(<View />, 1)).toLowPriorityWarnDev(
'componentWillReceiveProps has been renamed to UNSAFE_componentWillReceiveProps, ' +
"and the old name won't work in the next major version of React.\n\n" +
'We suggest doing one of the following:\n' +
"- If you're updating state whenever props change, " +
'move this logic into static getDerivedStateFromProps.\n' +
'- If you fetch data or perform other side effects in componentWillReceiveProps, ' +
'move this logic into componentDidUpdate.\n' +
'- Refactor your code to use memoization techniques instead of derived state. ' +
'Learn more at: https://fb.me/react-derived-state\n' +
'- To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles <path/to/code>` in your project folder. ' +
'(Note that the warning will still be logged in strict mode.)\n' +
'\nPlease update the following components: MyNativeComponent\n',
{withoutStack: true},
);
});
});
});