File tree 3 files changed +29
-3
lines changed
3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change
1
+ /* eslint-env mocha */
2
+ import ReactDOM from "react-dom" ;
3
+ import sinon from "sinon" ;
4
+ import { mcontent , renderModal , emptyDOM } from "./helper" ;
5
+
6
+ export default ( ) => {
7
+ afterEach ( "cleaned up all rendered modals" , emptyDOM ) ;
8
+
9
+ it ( "renders as expected, initially" , ( ) => {
10
+ const modal = renderModal ( { isOpen : true } , "hello" ) ;
11
+ mcontent ( modal ) . should . be . ok ( ) ;
12
+ } ) ;
13
+
14
+ it ( "allows ReactDOM.createPortal to be overridden in real-time" , ( ) => {
15
+ const createPortalSpy = sinon . spy ( ReactDOM , "createPortal" ) ;
16
+ renderModal ( { isOpen : true } , "hello" ) ;
17
+ createPortalSpy . called . should . be . ok ( ) ;
18
+ ReactDOM . createPortal . restore ( ) ;
19
+ } ) ;
20
+ } ;
Original file line number Diff line number Diff line change @@ -4,8 +4,10 @@ import ModalState from "./Modal.spec";
4
4
import ModalEvents from "./Modal.events.spec" ;
5
5
import ModalStyle from "./Modal.style.spec" ;
6
6
import ModalHelpers from "./Modal.helpers.spec" ;
7
+ import ModalTestability from "./Modal.testability.spec" ;
7
8
8
9
describe ( "State" , ModalState ) ;
9
10
describe ( "Style" , ModalStyle ) ;
10
11
describe ( "Events" , ModalEvents ) ;
11
12
describe ( "Helpers" , ModalHelpers ) ;
13
+ describe ( "Testability" , ModalTestability ) ;
Original file line number Diff line number Diff line change @@ -11,9 +11,11 @@ export const portalClassName = "ReactModalPortal";
11
11
export const bodyOpenClassName = "ReactModal__Body--open" ;
12
12
13
13
const isReact16 = ReactDOM . createPortal !== undefined ;
14
- const createPortal = isReact16
15
- ? ReactDOM . createPortal
16
- : ReactDOM . unstable_renderSubtreeIntoContainer ;
14
+
15
+ const getCreatePortal = ( ) =>
16
+ isReact16
17
+ ? ReactDOM . createPortal
18
+ : ReactDOM . unstable_renderSubtreeIntoContainer ;
17
19
18
20
function getParentElement ( parentSelector ) {
19
21
return parentSelector ( ) ;
@@ -180,6 +182,7 @@ class Modal extends Component {
180
182
} ;
181
183
182
184
renderPortal = props => {
185
+ const createPortal = getCreatePortal ( ) ;
183
186
const portal = createPortal (
184
187
this ,
185
188
< ModalPortal defaultStyles = { Modal . defaultStyles } { ...props } /> ,
@@ -197,6 +200,7 @@ class Modal extends Component {
197
200
this . node = document . createElement ( "div" ) ;
198
201
}
199
202
203
+ const createPortal = getCreatePortal ( ) ;
200
204
return createPortal (
201
205
< ModalPortal
202
206
ref = { this . portalRef }
You can’t perform that action at this time.
0 commit comments