File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
packages/react-test-renderer/src Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 88 */
99
1010import emptyObject from 'fbjs/lib/emptyObject' ;
11+ import warning from 'fbjs/lib/warning' ;
1112
1213import * as TestRendererScheduling from './ReactTestRendererScheduling' ;
1314
@@ -57,6 +58,15 @@ export function appendChild(
5758 parentInstance : Instance | Container ,
5859 child : Instance | TextInstance ,
5960) : void {
61+ if ( __DEV__ ) {
62+ warning (
63+ typeof parentInstance . children . indexOf === 'function' ,
64+ 'An invalid container has been provided. ' +
65+ 'This may indicate that another render is being used in addition to the test renderer. ' +
66+ '(For example, ReactDOM.createPortal inside of a ReactTestRenderer tree.) ' +
67+ 'This is not supported.' ,
68+ ) ;
69+ }
6070 const index = parentInstance . children . indexOf ( child ) ;
6171 if ( index !== - 1 ) {
6272 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+ } ) ;
27+ } ) ;
You can’t perform that action at this time.
0 commit comments