11
11
12
12
const React = require ( 'react' ) ;
13
13
const ReactDOM = require ( 'react-dom' ) ;
14
- const findDOMNode =
15
- ReactDOM . __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED . findDOMNode ;
16
14
const StrictMode = React . StrictMode ;
17
15
18
16
describe ( 'findDOMNode' , ( ) => {
17
+ // @gate www
19
18
it ( 'findDOMNode should return null if passed null' , ( ) => {
20
- expect ( findDOMNode ( null ) ) . toBe ( null ) ;
19
+ expect ( ReactDOM . findDOMNode ( null ) ) . toBe ( null ) ;
21
20
} ) ;
22
21
23
- // @gate !disableLegacyMode
22
+ // @gate www && !disableLegacyMode
24
23
it ( 'findDOMNode should find dom element' , ( ) => {
25
24
class MyNode extends React . Component {
26
25
render ( ) {
@@ -34,13 +33,13 @@ describe('findDOMNode', () => {
34
33
35
34
const container = document . createElement ( 'div' ) ;
36
35
const myNode = ReactDOM . render ( < MyNode /> , container ) ;
37
- const myDiv = findDOMNode ( myNode ) ;
38
- const mySameDiv = findDOMNode ( myDiv ) ;
36
+ const myDiv = ReactDOM . findDOMNode ( myNode ) ;
37
+ const mySameDiv = ReactDOM . findDOMNode ( myDiv ) ;
39
38
expect ( myDiv . tagName ) . toBe ( 'DIV' ) ;
40
39
expect ( mySameDiv ) . toBe ( myDiv ) ;
41
40
} ) ;
42
41
43
- // @gate !disableLegacyMode
42
+ // @gate www && !disableLegacyMode
44
43
it ( 'findDOMNode should find dom element after an update from null' , ( ) => {
45
44
function Bar ( { flag} ) {
46
45
if ( flag ) {
@@ -57,23 +56,24 @@ describe('findDOMNode', () => {
57
56
const container = document . createElement ( 'div' ) ;
58
57
59
58
const myNodeA = ReactDOM . render ( < MyNode /> , container ) ;
60
- const a = findDOMNode ( myNodeA ) ;
59
+ const a = ReactDOM . findDOMNode ( myNodeA ) ;
61
60
expect ( a ) . toBe ( null ) ;
62
61
63
62
const myNodeB = ReactDOM . render ( < MyNode flag = { true } /> , container ) ;
64
63
expect ( myNodeA === myNodeB ) . toBe ( true ) ;
65
64
66
- const b = findDOMNode ( myNodeB ) ;
65
+ const b = ReactDOM . findDOMNode ( myNodeB ) ;
67
66
expect ( b . tagName ) . toBe ( 'SPAN' ) ;
68
67
} ) ;
69
68
69
+ // @gate www
70
70
it ( 'findDOMNode should reject random objects' , ( ) => {
71
71
expect ( function ( ) {
72
- findDOMNode ( { foo : 'bar' } ) ;
72
+ ReactDOM . findDOMNode ( { foo : 'bar' } ) ;
73
73
} ) . toThrowError ( 'Argument appears to not be a ReactComponent. Keys: foo' ) ;
74
74
} ) ;
75
75
76
- // @gate !disableLegacyMode
76
+ // @gate www && !disableLegacyMode
77
77
it ( 'findDOMNode should reject unmounted objects with render func' , ( ) => {
78
78
class Foo extends React . Component {
79
79
render ( ) {
@@ -85,16 +85,16 @@ describe('findDOMNode', () => {
85
85
const inst = ReactDOM . render ( < Foo /> , container ) ;
86
86
ReactDOM . unmountComponentAtNode ( container ) ;
87
87
88
- expect ( ( ) => findDOMNode ( inst ) ) . toThrowError (
88
+ expect ( ( ) => ReactDOM . findDOMNode ( inst ) ) . toThrowError (
89
89
'Unable to find node on an unmounted component.' ,
90
90
) ;
91
91
} ) ;
92
92
93
- // @gate !disableLegacyMode
93
+ // @gate www && !disableLegacyMode
94
94
it ( 'findDOMNode should not throw an error when called within a component that is not mounted' , ( ) => {
95
95
class Bar extends React . Component {
96
96
UNSAFE_componentWillMount ( ) {
97
- expect ( findDOMNode ( this ) ) . toBeNull ( ) ;
97
+ expect ( ReactDOM . findDOMNode ( this ) ) . toBeNull ( ) ;
98
98
}
99
99
100
100
render ( ) {
@@ -107,7 +107,7 @@ describe('findDOMNode', () => {
107
107
} ) . not . toThrow ( ) ;
108
108
} ) ;
109
109
110
- // @gate !disableLegacyMode
110
+ // @gate www && !disableLegacyMode
111
111
it ( 'findDOMNode should warn if used to find a host component inside StrictMode' , ( ) => {
112
112
let parent = undefined ;
113
113
let child = undefined ;
@@ -129,7 +129,7 @@ describe('findDOMNode', () => {
129
129
) ;
130
130
131
131
let match ;
132
- expect ( ( ) => ( match = findDOMNode ( parent ) ) ) . toErrorDev ( [
132
+ expect ( ( ) => ( match = ReactDOM . findDOMNode ( parent ) ) ) . toErrorDev ( [
133
133
'Warning: findDOMNode is deprecated in StrictMode. ' +
134
134
'findDOMNode was passed an instance of ContainsStrictModeChild which renders StrictMode children. ' +
135
135
'Instead, add a ref directly to the element you want to reference. ' +
@@ -141,7 +141,7 @@ describe('findDOMNode', () => {
141
141
expect ( match ) . toBe ( child ) ;
142
142
} ) ;
143
143
144
- // @gate !disableLegacyMode
144
+ // @gate www && !disableLegacyMode
145
145
it ( 'findDOMNode should warn if passed a component that is inside StrictMode' , ( ) => {
146
146
let parent = undefined ;
147
147
let child = undefined ;
@@ -162,7 +162,7 @@ describe('findDOMNode', () => {
162
162
) ;
163
163
164
164
let match ;
165
- expect ( ( ) => ( match = findDOMNode ( parent ) ) ) . toErrorDev ( [
165
+ expect ( ( ) => ( match = ReactDOM . findDOMNode ( parent ) ) ) . toErrorDev ( [
166
166
'Warning: findDOMNode is deprecated in StrictMode. ' +
167
167
'findDOMNode was passed an instance of IsInStrictMode which is inside StrictMode. ' +
168
168
'Instead, add a ref directly to the element you want to reference. ' +
0 commit comments