File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 77 * @flow
88 */
99
10+ import warning from 'shared/warning' ;
1011import * as TestRendererScheduling from './ReactTestRendererScheduling' ;
1112
1213export type Type = string ;
@@ -62,6 +63,15 @@ export function appendChild(
6263 parentInstance : Instance | Container ,
6364 child : Instance | TextInstance ,
6465) : void {
66+ if ( __DEV__ ) {
67+ warning (
68+ Array . isArray ( parentInstance . children ) ,
69+ 'An invalid container has been provided. ' +
70+ 'This may indicate that another render is being used in addition to the test renderer. ' +
71+ '(For example, ReactDOM.createPortal inside of a ReactTestRenderer tree.) ' +
72+ 'This is not supported.' ,
73+ ) ;
74+ }
6575 const index = parentInstance . children . indexOf ( child ) ;
6676 if ( index !== - 1 ) {
6777 parentInstance . children . splice ( index , 1 ) ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Copyright (c) 2013-present, Facebook, Inc.
3+ *
4+ * This source code is licensed under the MIT license found in the
5+ * LICENSE file in the root directory of this source tree.
6+ *
7+ * @emails react-core
8+ */
9+
10+ 'use strict' ;
11+
12+ const ReactDOM = require ( 'react-dom' ) ;
13+
14+ // Isolate test renderer.
15+ jest . resetModules ( ) ;
16+ const ReactTestRenderer = require ( 'react-test-renderer' ) ;
17+
18+ describe ( 'ReactTestRenderer' , ( ) => {
19+ it ( 'should warn if used to render a ReactDOM portal' , ( ) => {
20+ const container = document . createElement ( 'div' ) ;
21+ expect ( ( ) => {
22+ expect ( ( ) => {
23+ ReactTestRenderer . create ( ReactDOM . createPortal ( 'foo' , container ) ) ;
24+ } ) . toThrow ( ) ;
25+ } ) . toWarnDev ( 'An invalid container has been provided.' , {
26+ withoutStack : true ,
27+ } ) ;
28+ } ) ;
29+ } ) ;
You can’t perform that action at this time.
0 commit comments