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