File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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";
44import ModalEvents from "./Modal.events.spec" ;
55import ModalStyle from "./Modal.style.spec" ;
66import ModalHelpers from "./Modal.helpers.spec" ;
7+ import ModalTestability from "./Modal.testability.spec" ;
78
89describe ( "State" , ModalState ) ;
910describe ( "Style" , ModalStyle ) ;
1011describe ( "Events" , ModalEvents ) ;
1112describe ( "Helpers" , ModalHelpers ) ;
13+ describe ( "Testability" , ModalTestability ) ;
Original file line number Diff line number Diff line change @@ -11,9 +11,11 @@ export const portalClassName = "ReactModalPortal";
1111export const bodyOpenClassName = "ReactModal__Body--open" ;
1212
1313const 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 ;
1719
1820function getParentElement ( parentSelector ) {
1921 return parentSelector ( ) ;
@@ -180,6 +182,7 @@ class Modal extends Component {
180182 } ;
181183
182184 renderPortal = props => {
185+ const createPortal = getCreatePortal ( ) ;
183186 const portal = createPortal (
184187 this ,
185188 < ModalPortal defaultStyles = { Modal . defaultStyles } { ...props } /> ,
@@ -197,6 +200,7 @@ class Modal extends Component {
197200 this . node = document . createElement ( "div" ) ;
198201 }
199202
203+ const createPortal = getCreatePortal ( ) ;
200204 return createPortal (
201205 < ModalPortal
202206 ref = { this . portalRef }
You can’t perform that action at this time.
0 commit comments