@@ -240,9 +240,14 @@ describe('Modal', () => {
240
240
} )
241
241
242
242
describe ( 'true' , ( ) => {
243
- it ( 'adds classes "dimmable dimmed" to the body' , ( ) => {
243
+ it ( 'adds/removes body classes "dimmable dimmed" on mount/unmount' , ( ) => {
244
+ assertBodyClasses ( 'dimmable' , 'dimmed' , false )
245
+
244
246
wrapperMount ( < Modal open dimmer /> )
245
247
assertBodyClasses ( 'dimmable' , 'dimmed' )
248
+
249
+ wrapper . unmount ( )
250
+ assertBodyClasses ( 'dimmable' , 'dimmed' , false )
246
251
} )
247
252
248
253
it ( 'adds a dimmer to the body' , ( ) => {
@@ -264,9 +269,14 @@ describe('Modal', () => {
264
269
} )
265
270
266
271
describe ( 'blurring' , ( ) => {
267
- it ( 'adds class "dimmable dimmed blurring" to the body' , ( ) => {
272
+ it ( 'adds/removes body classes "dimmable dimmed blurring" on mount/unmount' , ( ) => {
273
+ assertBodyClasses ( 'dimmable' , 'dimmed' , 'blurring' , false )
274
+
268
275
wrapperMount ( < Modal open dimmer = 'blurring' /> )
269
276
assertBodyClasses ( 'dimmable' , 'dimmed' , 'blurring' )
277
+
278
+ wrapper . unmount ( )
279
+ assertBodyClasses ( 'dimmable' , 'dimmed' , 'blurring' , false )
270
280
} )
271
281
272
282
it ( 'adds a dimmer to the body' , ( ) => {
@@ -276,10 +286,14 @@ describe('Modal', () => {
276
286
} )
277
287
278
288
describe ( 'inverted' , ( ) => {
279
- it ( 'adds class "dimmable dimmed" to the body' , ( ) => {
280
- wrapperMount ( < Modal open dimmer = 'inverted' /> )
289
+ it ( 'adds/removes body classes "dimmable dimmed" on mount/unmount' , ( ) => {
290
+ assertBodyClasses ( 'dimmable' , 'dimmed' , false )
291
+
292
+ wrapperMount ( < Modal open dimmer /> )
281
293
assertBodyClasses ( 'dimmable' , 'dimmed' )
282
- assertBodyClasses ( 'inverted' , false )
294
+
295
+ wrapper . unmount ( )
296
+ assertBodyClasses ( 'dimmable' , 'dimmed' , false )
283
297
} )
284
298
285
299
it ( 'adds an inverted dimmer to the body' , ( ) => {
@@ -460,27 +474,32 @@ describe('Modal', () => {
460
474
} )
461
475
462
476
describe ( 'scrolling' , ( ) => {
477
+ const innerHeight = window . innerHeight
478
+
463
479
afterEach ( ( ) => {
464
480
document . body . classList . remove ( 'scrolling' )
465
481
} )
466
482
483
+ after ( ( ) => {
484
+ window . innerHeight = innerHeight
485
+ } )
486
+
467
487
it ( 'does not add the scrolling class to the body by default' , ( ) => {
468
488
wrapperMount ( < Modal open /> )
469
489
assertBodyClasses ( 'scrolling' , false )
470
490
} )
471
491
472
492
it ( 'adds the scrolling class to the body when taller than the window' , ( done ) => {
473
- wrapperMount ( < Modal open > foo</ Modal > )
474
-
475
493
window . innerHeight = 10
494
+ wrapperMount ( < Modal open > foo</ Modal > )
476
495
477
496
requestAnimationFrame ( ( ) => {
478
497
assertBodyClasses ( 'scrolling' )
479
498
done ( )
480
499
} )
481
500
} )
482
501
483
- it ( 'removes the scrolling class from the body when the window grows taller ' , ( done ) => {
502
+ it ( 'adds/ removes the scrolling class to the body when the window grows/shrinks ' , ( done ) => {
484
503
assertBodyClasses ( 'scrolling' , false )
485
504
486
505
wrapperMount ( < Modal open > foo</ Modal > )
@@ -496,5 +515,20 @@ describe('Modal', () => {
496
515
} )
497
516
} )
498
517
} )
518
+
519
+ it ( 'removes the scrolling class from the body on unmount' , ( done ) => {
520
+ assertBodyClasses ( 'scrolling' , false )
521
+
522
+ window . innerHeight = 10
523
+ wrapperMount ( < Modal open > foo</ Modal > )
524
+
525
+ requestAnimationFrame ( ( ) => {
526
+ assertBodyClasses ( 'scrolling' )
527
+ wrapper . unmount ( )
528
+
529
+ assertBodyClasses ( 'scrolling' , false )
530
+ done ( )
531
+ } )
532
+ } )
499
533
} )
500
534
} )
0 commit comments