18
18
let PropTypes ;
19
19
let React ;
20
20
let ReactDOMClient ;
21
- let ReactDOMServer ;
22
21
let ReactTestUtils ;
23
22
let act ;
24
23
@@ -29,7 +28,6 @@ describe('ReactContextValidator', () => {
29
28
PropTypes = require ( 'prop-types' ) ;
30
29
React = require ( 'react' ) ;
31
30
ReactDOMClient = require ( 'react-dom/client' ) ;
32
- ReactDOMServer = require ( 'react-dom/server' ) ;
33
31
ReactTestUtils = require ( 'react-dom/test-utils' ) ;
34
32
act = require ( 'internal-test-utils' ) . act ;
35
33
} ) ;
@@ -159,136 +157,6 @@ describe('ReactContextValidator', () => {
159
157
expect ( componentDidUpdateContext ) . toEqual ( { foo : 'def' } ) ;
160
158
} ) ;
161
159
162
- // @gate !disableLegacyContext || !__DEV__
163
- it ( 'should check context types' , ( ) => {
164
- class Component extends React . Component {
165
- render ( ) {
166
- return < div /> ;
167
- }
168
- }
169
- Component . contextTypes = {
170
- foo : PropTypes . string . isRequired ,
171
- } ;
172
-
173
- expect ( ( ) => ReactTestUtils . renderIntoDocument ( < Component /> ) ) . toErrorDev (
174
- 'Warning: Failed context type: ' +
175
- 'The context `foo` is marked as required in `Component`, but its value ' +
176
- 'is `undefined`.\n' +
177
- ' in Component (at **)' ,
178
- ) ;
179
-
180
- class ComponentInFooStringContext extends React . Component {
181
- getChildContext ( ) {
182
- return {
183
- foo : this . props . fooValue ,
184
- } ;
185
- }
186
-
187
- render ( ) {
188
- return < Component /> ;
189
- }
190
- }
191
- ComponentInFooStringContext . childContextTypes = {
192
- foo : PropTypes . string ,
193
- } ;
194
-
195
- // No additional errors expected
196
- ReactTestUtils . renderIntoDocument (
197
- < ComponentInFooStringContext fooValue = { 'bar' } /> ,
198
- ) ;
199
-
200
- class ComponentInFooNumberContext extends React . Component {
201
- getChildContext ( ) {
202
- return {
203
- foo : this . props . fooValue ,
204
- } ;
205
- }
206
-
207
- render ( ) {
208
- return < Component /> ;
209
- }
210
- }
211
- ComponentInFooNumberContext . childContextTypes = {
212
- foo : PropTypes . number ,
213
- } ;
214
-
215
- expect ( ( ) =>
216
- ReactTestUtils . renderIntoDocument (
217
- < ComponentInFooNumberContext fooValue = { 123 } /> ,
218
- ) ,
219
- ) . toErrorDev (
220
- 'Warning: Failed context type: ' +
221
- 'Invalid context `foo` of type `number` supplied ' +
222
- 'to `Component`, expected `string`.\n' +
223
- ' in Component (at **)\n' +
224
- ' in ComponentInFooNumberContext (at **)' ,
225
- ) ;
226
- } ) ;
227
-
228
- // @gate !disableLegacyContext || !__DEV__
229
- it ( 'should check child context types' , ( ) => {
230
- class Component extends React . Component {
231
- getChildContext ( ) {
232
- return this . props . testContext ;
233
- }
234
-
235
- render ( ) {
236
- return < div /> ;
237
- }
238
- }
239
- Component . childContextTypes = {
240
- foo : PropTypes . string . isRequired ,
241
- bar : PropTypes . number ,
242
- } ;
243
-
244
- expect ( ( ) =>
245
- ReactTestUtils . renderIntoDocument ( < Component testContext = { { bar : 123 } } /> ) ,
246
- ) . toErrorDev (
247
- 'Warning: Failed child context type: ' +
248
- 'The child context `foo` is marked as required in `Component`, but its ' +
249
- 'value is `undefined`.\n' +
250
- ' in Component (at **)' ,
251
- ) ;
252
-
253
- expect ( ( ) =>
254
- ReactTestUtils . renderIntoDocument ( < Component testContext = { { foo : 123 } } /> ) ,
255
- ) . toErrorDev (
256
- 'Warning: Failed child context type: ' +
257
- 'Invalid child context `foo` of type `number` ' +
258
- 'supplied to `Component`, expected `string`.\n' +
259
- ' in Component (at **)' ,
260
- ) ;
261
-
262
- // No additional errors expected
263
- ReactTestUtils . renderIntoDocument (
264
- < Component testContext = { { foo : 'foo' , bar : 123 } } /> ,
265
- ) ;
266
-
267
- ReactTestUtils . renderIntoDocument ( < Component testContext = { { foo : 'foo' } } /> ) ;
268
- } ) ;
269
-
270
- it ( 'warns of incorrect prop types on context provider' , ( ) => {
271
- const TestContext = React . createContext ( ) ;
272
-
273
- TestContext . Provider . propTypes = {
274
- value : PropTypes . string . isRequired ,
275
- } ;
276
-
277
- ReactTestUtils . renderIntoDocument ( < TestContext . Provider value = "val" /> ) ;
278
-
279
- class Component extends React . Component {
280
- render ( ) {
281
- return < TestContext . Provider value = { undefined } /> ;
282
- }
283
- }
284
-
285
- expect ( ( ) => ReactTestUtils . renderIntoDocument ( < Component /> ) ) . toErrorDev (
286
- 'Warning: Failed prop type: The prop `value` is marked as required in ' +
287
- '`Context.Provider`, but its value is `undefined`.\n' +
288
- ' in Component (at **)' ,
289
- ) ;
290
- } ) ;
291
-
292
160
// TODO (bvaughn) Remove this test and the associated behavior in the future.
293
161
// It has only been added in Fiber to match the (unintentional) behavior in Stack.
294
162
// @gate !disableLegacyContext || !__DEV__
@@ -371,8 +239,6 @@ describe('ReactContextValidator', () => {
371
239
'Warning: MiddleMissingContext.childContextTypes is specified but there is no ' +
372
240
'getChildContext() method on the instance. You can either define getChildContext() ' +
373
241
'on MiddleMissingContext or remove childContextTypes from it.' ,
374
- 'Warning: Failed context type: The context `bar` is marked as required ' +
375
- 'in `ChildContextConsumer`, but its value is `undefined`.' ,
376
242
] ) ;
377
243
expect ( childContext . bar ) . toBeUndefined ( ) ;
378
244
expect ( childContext . foo ) . toBe ( 'FOO' ) ;
@@ -699,24 +565,4 @@ describe('ReactContextValidator', () => {
699
565
'Warning: ComponentB: Function components do not support contextType.' ,
700
566
) ;
701
567
} ) ;
702
-
703
- it ( 'should honor a displayName if set on the context type' , ( ) => {
704
- const Context = React . createContext ( null ) ;
705
- Context . displayName = 'MyContextType' ;
706
- function Validator ( ) {
707
- return null ;
708
- }
709
- Validator . propTypes = { dontPassToSeeErrorStack : PropTypes . bool . isRequired } ;
710
-
711
- expect ( ( ) => {
712
- ReactDOMServer . renderToStaticMarkup (
713
- < Context . Provider >
714
- < Context . Consumer > { ( ) => < Validator /> } </ Context . Consumer >
715
- </ Context . Provider > ,
716
- ) ;
717
- } ) . toErrorDev (
718
- 'Warning: Failed prop type: The prop `dontPassToSeeErrorStack` is marked as required in `Validator`, but its value is `undefined`.\n' +
719
- ' in Validator (at **)' ,
720
- ) ;
721
- } ) ;
722
568
} ) ;
0 commit comments