@@ -2417,17 +2417,18 @@ describe('make sure that we can create an injector outside of tests', function()
2417
2417
} ) ;
2418
2418
2419
2419
2420
- describe ( 'don\'t leak memory between tests' , function ( ) {
2421
- var jQuery = window . jQuery ;
2422
- var prevRootElement ;
2423
- var prevRemoveDataSpy ;
2424
- var prevCleanDataSpy ;
2425
-
2426
- it ( 'should run a test to keep track of `removeData()`/`cleanData()` calls for later inspection' ,
2427
- function ( ) {
2420
+ describe ( '`afterEach` clean-up' , function ( ) {
2421
+ describe ( 'undecorated `$rootElement`' , function ( ) {
2422
+ var jQuery = window . jQuery ;
2423
+ var prevRootElement ;
2424
+ var prevRemoveDataSpy ;
2425
+ var prevCleanDataSpy ;
2426
+
2427
+
2428
+ it ( 'should set up spies so the next test can verify `$rootElement` was cleaned up' , function ( ) {
2428
2429
module ( function ( $provide ) {
2429
2430
$provide . decorator ( '$rootElement' , function ( $delegate ) {
2430
- // Spy on `.removeData()` and `jQuery.cleanData()`,
2431
+ // Spy on `$rootElement .removeData()` and `jQuery.cleanData()`,
2431
2432
// so the next test can verify that they have been called as necessary
2432
2433
prevRootElement = $delegate ;
2433
2434
prevRemoveDataSpy = spyOn ( $delegate , 'removeData' ) . andCallThrough ( ) ;
@@ -2444,44 +2445,45 @@ describe('don\'t leak memory between tests', function() {
2444
2445
inject ( function ( $rootElement ) {
2445
2446
expect ( $rootElement . injector ( ) ) . toBeDefined ( ) ;
2446
2447
} ) ;
2447
- }
2448
- ) ;
2448
+ } ) ;
2449
2449
2450
- it ( 'should clean up `$rootElement`-related data after each test' , function ( ) {
2451
- // One call is made by `testabilityPatch`'s `dealoc()`
2452
- // We want to verify the subsequent call, made by `angular-mocks`
2453
- // (Since `testabilityPatch` re-wrapps `$rootElement` and because jQuery
2454
- // returns a different object, we don't capture the 1st call when using jQuery)
2455
- expect ( prevRemoveDataSpy . callCount ) . toBe ( jQuery ? 1 : 2 ) ;
2456
2450
2457
- if ( jQuery ) {
2451
+ it ( 'should clean up `$rootElement` after each test' , function ( ) {
2458
2452
// One call is made by `testabilityPatch`'s `dealoc()`
2459
2453
// We want to verify the subsequent call, made by `angular-mocks`
2460
- expect ( prevCleanDataSpy . callCount ) . toBe ( 2 ) ;
2454
+ // (Since `testabilityPatch` re-wrapps `$rootElement` and because jQuery returns a different
2455
+ // object when re-wrapping, we don't capture the 1st call when using jQuery)
2456
+ expect ( prevRemoveDataSpy . callCount ) . toBe ( jQuery ? 1 : 2 ) ;
2461
2457
2462
- var cleanUpElems = prevCleanDataSpy . calls [ 1 ] . args [ 0 ] ;
2463
- expect ( cleanUpElems . length ) . toBe ( 1 ) ;
2464
- expect ( cleanUpElems [ 0 ] [ 0 ] ) . toBe ( prevRootElement [ 0 ] ) ;
2465
- }
2458
+ if ( jQuery ) {
2459
+ // One call is made by `testabilityPatch`'s `dealoc()`
2460
+ // We want to verify the subsequent call, made by `angular-mocks`
2461
+ expect ( prevCleanDataSpy . callCount ) . toBe ( 2 ) ;
2462
+
2463
+ var cleanUpElems = prevCleanDataSpy . calls [ 1 ] . args [ 0 ] ;
2464
+ expect ( cleanUpElems . length ) . toBe ( 1 ) ;
2465
+ expect ( cleanUpElems [ 0 ] [ 0 ] ) . toBe ( prevRootElement [ 0 ] ) ;
2466
+ }
2467
+ } ) ;
2466
2468
} ) ;
2467
- } ) ;
2468
2469
2469
- describe ( 'don\'t leak memory between tests with mocked `$rootScope`' , function ( ) {
2470
- var jQuery = window . jQuery ;
2471
- var prevOriginalRootElement ;
2472
- var prevOriginalRemoveDataSpy ;
2473
- var prevRootElement ;
2474
- var prevRemoveDataSpy ;
2475
- var prevCleanDataSpy ;
2476
2470
2477
- it ( 'should run a test to keep track of `removeData()`/`cleanData()` calls for later inspection' ,
2478
- function ( ) {
2471
+ describe ( 'decorated `$rootElement`' , function ( ) {
2472
+ var jQuery = window . jQuery ;
2473
+ var prevOriginalRootElement ;
2474
+ var prevOriginalRemoveDataSpy ;
2475
+ var prevRootElement ;
2476
+ var prevRemoveDataSpy ;
2477
+ var prevCleanDataSpy ;
2478
+
2479
+
2480
+ it ( 'should set up spies so the next text can verify `$rootElement` was cleaned up' , function ( ) {
2479
2481
module ( function ( $provide ) {
2480
2482
$provide . decorator ( '$rootElement' , function ( $delegate ) {
2481
2483
// Mock `$rootElement` to be able to verify that the correct object is cleaned up
2482
2484
var mockRootElement = angular . element ( '<div></div>' ) ;
2483
2485
2484
- // Spy on `.removeData()` and `jQuery.cleanData()`,
2486
+ // Spy on `$rootElement .removeData()` and `jQuery.cleanData()`,
2485
2487
// so the next test can verify that they have been called as necessary
2486
2488
prevOriginalRootElement = $delegate ;
2487
2489
prevOriginalRemoveDataSpy = spyOn ( $delegate , 'removeData' ) . andCallThrough ( ) ;
@@ -2505,25 +2507,25 @@ describe('don\'t leak memory between tests with mocked `$rootScope`', function()
2505
2507
2506
2508
// If we don't clean up `prevOriginalRootElement`-related data now, `testabilityPatch` will
2507
2509
// complain about a memory leak, because it doesn't clean up after the original
2508
- // `$rootElement`.
2509
- // This is a false alarm, because `angular-mocks` will clean up later.
2510
+ // `$rootElement`
2511
+ // This is a false alarm, because `angular-mocks` would have cleaned up in a subsequent
2512
+ // `afterEach` block
2510
2513
prevOriginalRootElement . removeData ( ) ;
2511
2514
prevOriginalRemoveDataSpy . reset ( ) ;
2512
2515
2513
2516
expect ( prevOriginalRemoveDataSpy . callCount ) . toBe ( 0 ) ;
2514
2517
} ) ;
2515
- }
2516
- ) ;
2518
+ } ) ;
2519
+
2517
2520
2518
- it ( 'should clean up after the `$rootElement` (both original and decorated) after each test' ,
2519
- function ( ) {
2521
+ it ( 'should clean up `$rootElement` (both original and decorated) after each test' , function ( ) {
2520
2522
// Only `angular-mocks` cleans up after the original `$rootElement`, not `testabilityPatch`
2521
2523
expect ( prevOriginalRemoveDataSpy . callCount ) . toBe ( 1 ) ;
2522
2524
2523
2525
// One call is made by `testabilityPatch`'s `dealoc()`
2524
2526
// We want to verify the subsequent call, made by `angular-mocks`
2525
- // (Since `testabilityPatch` re-wrapps `$rootElement` and because jQuery
2526
- // returns a different object , we don't capture the 1st call when using jQuery)
2527
+ // (Since `testabilityPatch` re-wrapps `$rootElement` and because jQuery returns a different
2528
+ // object when re-wrapping , we don't capture the 1st call when using jQuery)
2527
2529
expect ( prevRemoveDataSpy . callCount ) . toBe ( jQuery ? 1 : 2 ) ;
2528
2530
2529
2531
if ( jQuery ) {
@@ -2536,6 +2538,6 @@ describe('don\'t leak memory between tests with mocked `$rootScope`', function()
2536
2538
expect ( cleanUpElems [ 0 ] [ 0 ] ) . toBe ( prevOriginalRootElement [ 0 ] ) ;
2537
2539
expect ( cleanUpElems [ 1 ] [ 0 ] ) . toBe ( prevRootElement [ 0 ] ) ;
2538
2540
}
2539
- }
2540
- ) ;
2541
+ } ) ;
2542
+ } ) ;
2541
2543
} ) ;
0 commit comments