@@ -112,17 +112,21 @@ describe('Modal', () => {
112
112
} ) ;
113
113
114
114
it ( 'give back focus to previous element or modal.' , ( done ) => {
115
+ function cleanup ( ) {
116
+ unmountModal ( ) ;
117
+ done ( ) ;
118
+ }
115
119
const modal = renderModal ( {
116
120
isOpen : true ,
117
121
onRequestClose ( ) {
118
- unmountModal ( ) ;
119
- done ( ) ;
122
+ cleanup ( ) ;
120
123
}
121
124
} , null , ( ) => { } ) ;
122
125
123
126
renderModal ( {
124
127
isOpen : true ,
125
128
onRequestClose ( ) {
129
+ unmountModal ( ) ;
126
130
Simulate . keyDown ( modal . portal . content , {
127
131
// The keyCode is all that matters, so this works
128
132
key : 'FakeKeyToTestLater' ,
@@ -175,6 +179,7 @@ describe('Modal', () => {
175
179
preventDefault ( ) { tabPrevented = true ; }
176
180
} ) ;
177
181
expect ( tabPrevented ) . toEqual ( true ) ;
182
+ unmountModal ( ) ;
178
183
} ) ;
179
184
180
185
it ( 'supports portalClassName' , ( ) => {
@@ -204,26 +209,31 @@ describe('Modal', () => {
204
209
it ( 'overrides the default styles when a custom overlayClassName is used' , ( ) => {
205
210
const modal = renderModal ( { isOpen : true , overlayClassName : 'myOverlayClass' } ) ;
206
211
expect ( modal . portal . overlay . style . backgroundColor ) . toEqual ( '' ) ;
212
+ unmountModal ( ) ;
207
213
} ) ;
208
214
209
215
it ( 'supports adding style to the modal contents' , ( ) => {
210
216
const modal = renderModal ( { isOpen : true , style : { content : { width : '20px' } } } ) ;
211
217
expect ( modal . portal . content . style . width ) . toEqual ( '20px' ) ;
218
+ unmountModal ( ) ;
212
219
} ) ;
213
220
214
221
it ( 'supports overriding style on the modal contents' , ( ) => {
215
222
const modal = renderModal ( { isOpen : true , style : { content : { position : 'static' } } } ) ;
216
223
expect ( modal . portal . content . style . position ) . toEqual ( 'static' ) ;
224
+ unmountModal ( ) ;
217
225
} ) ;
218
226
219
227
it ( 'supports adding style on the modal overlay' , ( ) => {
220
228
const modal = renderModal ( { isOpen : true , style : { overlay : { width : '75px' } } } ) ;
221
229
expect ( modal . portal . overlay . style . width ) . toEqual ( '75px' ) ;
230
+ unmountModal ( ) ;
222
231
} ) ;
223
232
224
233
it ( 'supports overriding style on the modal overlay' , ( ) => {
225
234
const modal = renderModal ( { isOpen : true , style : { overlay : { position : 'static' } } } ) ;
226
235
expect ( modal . portal . overlay . style . position ) . toEqual ( 'static' ) ;
236
+ unmountModal ( ) ;
227
237
} ) ;
228
238
229
239
it ( 'supports overriding the default styles' , ( ) => {
@@ -234,15 +244,27 @@ describe('Modal', () => {
234
244
const modal = renderModal ( { isOpen : true } ) ;
235
245
expect ( modal . portal . content . style . position ) . toEqual ( newStyle ) ;
236
246
Modal . defaultStyles . content . position = previousStyle ;
247
+ unmountModal ( ) ;
248
+ } ) ;
249
+
250
+
251
+ it ( 'should remove class from body when no modals opened' , ( ) => {
252
+ renderModal ( { isOpen : true } ) ;
253
+ renderModal ( { isOpen : true } ) ;
254
+ expect ( document . body . className . indexOf ( 'ReactModal__Body--open' ) > - 1 ) . toBe ( true ) ;
255
+ unmountModal ( ) ;
256
+ expect ( document . body . className . indexOf ( 'ReactModal__Body--open' ) > - 1 ) . toBe ( true ) ;
257
+ unmountModal ( ) ;
258
+ expect ( document . body . className . indexOf ( 'ReactModal__Body--open' ) === - 1 ) . toBe ( true ) ;
237
259
} ) ;
238
260
239
261
it ( 'adds class to body when open' , ( ) => {
240
262
renderModal ( { isOpen : false } ) ;
241
263
expect ( document . body . className . indexOf ( 'ReactModal__Body--open' ) !== - 1 ) . toEqual ( false ) ;
242
-
264
+ unmountModal ( ) ;
243
265
renderModal ( { isOpen : true } ) ;
244
- expect ( document . body . className . indexOf ( 'ReactModal__Body--open' ) !== - 1 ) . toEqual ( true ) ;
245
-
266
+ expect ( document . body . className . indexOf ( 'ReactModal__Body--open' ) > - 1 ) . toEqual ( true ) ;
267
+ unmountModal ( ) ;
246
268
renderModal ( { isOpen : false } ) ;
247
269
expect ( document . body . className . indexOf ( 'ReactModal__Body--open' ) !== - 1 ) . toEqual ( false ) ;
248
270
unmountModal ( ) ;
0 commit comments