6
6
*/
7
7
8
8
import { REACT_ELEMENT_TYPE , REACT_FRAGMENT_TYPE } from 'shared/ReactSymbols' ;
9
+ import { enableRefAsProp } from 'shared/ReactFeatureFlags' ;
9
10
10
11
import isArray from 'shared/isArray' ;
11
12
@@ -38,6 +39,34 @@ function assertYieldsWereCleared(root) {
38
39
}
39
40
}
40
41
42
+ function createJSXElementForTestComparison ( type , props ) {
43
+ if ( __DEV__ && enableRefAsProp ) {
44
+ const element = {
45
+ $$typeof : REACT_ELEMENT_TYPE ,
46
+ type : type ,
47
+ key : null ,
48
+ props : props ,
49
+ _owner : null ,
50
+ _store : __DEV__ ? { } : undefined ,
51
+ } ;
52
+ Object . defineProperty ( element , 'ref' , {
53
+ enumerable : false ,
54
+ value : null ,
55
+ } ) ;
56
+ return element ;
57
+ } else {
58
+ return {
59
+ $$typeof : REACT_ELEMENT_TYPE ,
60
+ type : type ,
61
+ key : null ,
62
+ ref : null ,
63
+ props : props ,
64
+ _owner : null ,
65
+ _store : __DEV__ ? { } : undefined ,
66
+ } ;
67
+ }
68
+ }
69
+
41
70
export function unstable_toMatchRenderedOutput ( root , expectedJSX ) {
42
71
assertYieldsWereCleared ( root ) ;
43
72
const actualJSON = root . toJSON ( ) ;
@@ -55,17 +84,9 @@ export function unstable_toMatchRenderedOutput(root, expectedJSX) {
55
84
if ( actualJSXChildren === null || typeof actualJSXChildren === 'string' ) {
56
85
actualJSX = actualJSXChildren ;
57
86
} else {
58
- actualJSX = {
59
- $$typeof : REACT_ELEMENT_TYPE ,
60
- type : REACT_FRAGMENT_TYPE ,
61
- key : null ,
62
- ref : null ,
63
- props : {
64
- children : actualJSXChildren ,
65
- } ,
66
- _owner : null ,
67
- _store : __DEV__ ? { } : undefined ,
68
- } ;
87
+ actualJSX = createJSXElementForTestComparison ( REACT_FRAGMENT_TYPE , {
88
+ children : actualJSXChildren ,
89
+ } ) ;
69
90
}
70
91
}
71
92
} else {
@@ -82,18 +103,12 @@ function jsonChildToJSXChild(jsonChild) {
82
103
return jsonChild ;
83
104
} else {
84
105
const jsxChildren = jsonChildrenToJSXChildren ( jsonChild . children ) ;
85
- return {
86
- $$typeof : REACT_ELEMENT_TYPE ,
87
- type : jsonChild . type ,
88
- key : null ,
89
- ref : null ,
90
- props :
91
- jsxChildren === null
92
- ? jsonChild . props
93
- : { ...jsonChild . props , children : jsxChildren } ,
94
- _owner : null ,
95
- _store : __DEV__ ? { } : undefined ,
96
- } ;
106
+ return createJSXElementForTestComparison (
107
+ jsonChild . type ,
108
+ jsxChildren === null
109
+ ? jsonChild . props
110
+ : { ...jsonChild . props , children : jsxChildren } ,
111
+ ) ;
97
112
}
98
113
}
99
114
0 commit comments