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