@@ -71,6 +71,7 @@ describe('ReactIs', () => {
71
71
72
72
it ( 'should identify context consumers' , ( ) => {
73
73
const Context = React . createContext ( false ) ;
74
+ expect ( ReactIs . isValidElementType ( Context . Consumer ) ) . toBe ( true ) ;
74
75
expect ( ReactIs . typeOf ( < Context . Consumer /> ) ) . toBe ( ReactIs . ContextConsumer ) ;
75
76
expect ( ReactIs . isContextConsumer ( < Context . Consumer /> ) ) . toBe ( true ) ;
76
77
expect ( ReactIs . isContextConsumer ( < Context . Provider /> ) ) . toBe ( false ) ;
@@ -79,6 +80,7 @@ describe('ReactIs', () => {
79
80
80
81
it ( 'should identify context providers' , ( ) => {
81
82
const Context = React . createContext ( false ) ;
83
+ expect ( ReactIs . isValidElementType ( Context . Provider ) ) . toBe ( true ) ;
82
84
expect ( ReactIs . typeOf ( < Context . Provider /> ) ) . toBe ( ReactIs . ContextProvider ) ;
83
85
expect ( ReactIs . isContextProvider ( < Context . Provider /> ) ) . toBe ( true ) ;
84
86
expect ( ReactIs . isContextProvider ( < Context . Consumer /> ) ) . toBe ( false ) ;
@@ -106,13 +108,15 @@ describe('ReactIs', () => {
106
108
107
109
it ( 'should identify ref forwarding component' , ( ) => {
108
110
const RefForwardingComponent = React . forwardRef ( ( props , ref ) => null ) ;
111
+ expect ( ReactIs . isValidElementType ( RefForwardingComponent ) ) . toBe ( true ) ;
109
112
expect ( ReactIs . typeOf ( < RefForwardingComponent /> ) ) . toBe ( ReactIs . ForwardRef ) ;
110
113
expect ( ReactIs . isForwardRef ( < RefForwardingComponent /> ) ) . toBe ( true ) ;
111
114
expect ( ReactIs . isForwardRef ( { type : ReactIs . StrictMode } ) ) . toBe ( false ) ;
112
115
expect ( ReactIs . isForwardRef ( < div /> ) ) . toBe ( false ) ;
113
116
} ) ;
114
117
115
118
it ( 'should identify fragments' , ( ) => {
119
+ expect ( ReactIs . isValidElementType ( React . Fragment ) ) . toBe ( true ) ;
116
120
expect ( ReactIs . typeOf ( < React . Fragment /> ) ) . toBe ( ReactIs . Fragment ) ;
117
121
expect ( ReactIs . isFragment ( < React . Fragment /> ) ) . toBe ( true ) ;
118
122
expect ( ReactIs . isFragment ( { type : ReactIs . Fragment } ) ) . toBe ( false ) ;
@@ -124,35 +128,40 @@ describe('ReactIs', () => {
124
128
it ( 'should identify portals' , ( ) => {
125
129
const div = document . createElement ( 'div' ) ;
126
130
const portal = ReactDOM . createPortal ( < div /> , div ) ;
131
+ expect ( ReactIs . isValidElementType ( portal ) ) . toBe ( false ) ;
127
132
expect ( ReactIs . typeOf ( portal ) ) . toBe ( ReactIs . Portal ) ;
128
133
expect ( ReactIs . isPortal ( portal ) ) . toBe ( true ) ;
129
134
expect ( ReactIs . isPortal ( div ) ) . toBe ( false ) ;
130
135
} ) ;
131
136
132
137
it ( 'should identify memo' , ( ) => {
133
138
const Component = ( ) => React . createElement ( 'div' ) ;
134
- const memoized = React . memo ( Component ) ;
135
- expect ( ReactIs . typeOf ( memoized ) ) . toBe ( ReactIs . Memo ) ;
136
- expect ( ReactIs . isMemo ( memoized ) ) . toBe ( true ) ;
137
- expect ( ReactIs . isMemo ( Component ) ) . toBe ( false ) ;
139
+ const Memoized = React . memo ( Component ) ;
140
+ expect ( ReactIs . isValidElementType ( Memoized ) ) . toBe ( true ) ;
141
+ expect ( ReactIs . typeOf ( < Memoized /> ) ) . toBe ( ReactIs . Memo ) ;
142
+ expect ( ReactIs . isMemo ( < Memoized /> ) ) . toBe ( true ) ;
143
+ expect ( ReactIs . isMemo ( < Component /> ) ) . toBe ( false ) ;
138
144
} ) ;
139
145
140
146
it ( 'should identify lazy' , ( ) => {
141
147
const Component = ( ) => React . createElement ( 'div' ) ;
142
- const lazyComponent = React . lazy ( ( ) => Component ) ;
143
- expect ( ReactIs . typeOf ( lazyComponent ) ) . toBe ( ReactIs . Lazy ) ;
144
- expect ( ReactIs . isLazy ( lazyComponent ) ) . toBe ( true ) ;
145
- expect ( ReactIs . isLazy ( Component ) ) . toBe ( false ) ;
148
+ const LazyComponent = React . lazy ( ( ) => Component ) ;
149
+ expect ( ReactIs . isValidElementType ( LazyComponent ) ) . toBe ( true ) ;
150
+ expect ( ReactIs . typeOf ( < LazyComponent /> ) ) . toBe ( ReactIs . Lazy ) ;
151
+ expect ( ReactIs . isLazy ( < LazyComponent /> ) ) . toBe ( true ) ;
152
+ expect ( ReactIs . isLazy ( < Component /> ) ) . toBe ( false ) ;
146
153
} ) ;
147
154
148
155
it ( 'should identify strict mode' , ( ) => {
156
+ expect ( ReactIs . isValidElementType ( React . StrictMode ) ) . toBe ( true ) ;
149
157
expect ( ReactIs . typeOf ( < React . StrictMode /> ) ) . toBe ( ReactIs . StrictMode ) ;
150
158
expect ( ReactIs . isStrictMode ( < React . StrictMode /> ) ) . toBe ( true ) ;
151
159
expect ( ReactIs . isStrictMode ( { type : ReactIs . StrictMode } ) ) . toBe ( false ) ;
152
160
expect ( ReactIs . isStrictMode ( < div /> ) ) . toBe ( false ) ;
153
161
} ) ;
154
162
155
163
it ( 'should identify suspense' , ( ) => {
164
+ expect ( ReactIs . isValidElementType ( React . Suspense ) ) . toBe ( true ) ;
156
165
expect ( ReactIs . typeOf ( < React . Suspense /> ) ) . toBe ( ReactIs . Suspense ) ;
157
166
expect ( ReactIs . isSuspense ( < React . Suspense /> ) ) . toBe ( true ) ;
158
167
expect ( ReactIs . isSuspense ( { type : ReactIs . Suspense } ) ) . toBe ( false ) ;
@@ -161,6 +170,7 @@ describe('ReactIs', () => {
161
170
} ) ;
162
171
163
172
it ( 'should identify profile root' , ( ) => {
173
+ expect ( ReactIs . isValidElementType ( React . Profiler ) ) . toBe ( true ) ;
164
174
expect (
165
175
ReactIs . typeOf ( < React . Profiler id = "foo" onRender = { jest . fn ( ) } /> ) ,
166
176
) . toBe ( ReactIs . Profiler ) ;
0 commit comments