Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 739d4c6

Browse files
committed
fixup 1
- Group into a `describe` block - Tweak test descriptions - Fix typos
1 parent 6825415 commit 739d4c6

File tree

1 file changed

+46
-44
lines changed

1 file changed

+46
-44
lines changed

test/ngMock/angular-mocksSpec.js

+46-44
Original file line numberDiff line numberDiff line change
@@ -2417,17 +2417,18 @@ describe('make sure that we can create an injector outside of tests', function()
24172417
});
24182418

24192419

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() {
24282429
module(function($provide) {
24292430
$provide.decorator('$rootElement', function($delegate) {
2430-
// Spy on `.removeData()` and `jQuery.cleanData()`,
2431+
// Spy on `$rootElement.removeData()` and `jQuery.cleanData()`,
24312432
// so the next test can verify that they have been called as necessary
24322433
prevRootElement = $delegate;
24332434
prevRemoveDataSpy = spyOn($delegate, 'removeData').andCallThrough();
@@ -2444,44 +2445,45 @@ describe('don\'t leak memory between tests', function() {
24442445
inject(function($rootElement) {
24452446
expect($rootElement.injector()).toBeDefined();
24462447
});
2447-
}
2448-
);
2448+
});
24492449

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);
24562450

2457-
if (jQuery) {
2451+
it('should clean up `$rootElement` after each test', function() {
24582452
// One call is made by `testabilityPatch`'s `dealoc()`
24592453
// 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);
24612457

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+
});
24662468
});
2467-
});
24682469

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;
24762470

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() {
24792481
module(function($provide) {
24802482
$provide.decorator('$rootElement', function($delegate) {
24812483
// Mock `$rootElement` to be able to verify that the correct object is cleaned up
24822484
var mockRootElement = angular.element('<div></div>');
24832485

2484-
// Spy on `.removeData()` and `jQuery.cleanData()`,
2486+
// Spy on `$rootElement.removeData()` and `jQuery.cleanData()`,
24852487
// so the next test can verify that they have been called as necessary
24862488
prevOriginalRootElement = $delegate;
24872489
prevOriginalRemoveDataSpy = spyOn($delegate, 'removeData').andCallThrough();
@@ -2505,25 +2507,25 @@ describe('don\'t leak memory between tests with mocked `$rootScope`', function()
25052507

25062508
// If we don't clean up `prevOriginalRootElement`-related data now, `testabilityPatch` will
25072509
// 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
25102513
prevOriginalRootElement.removeData();
25112514
prevOriginalRemoveDataSpy.reset();
25122515

25132516
expect(prevOriginalRemoveDataSpy.callCount).toBe(0);
25142517
});
2515-
}
2516-
);
2518+
});
2519+
25172520

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() {
25202522
// Only `angular-mocks` cleans up after the original `$rootElement`, not `testabilityPatch`
25212523
expect(prevOriginalRemoveDataSpy.callCount).toBe(1);
25222524

25232525
// One call is made by `testabilityPatch`'s `dealoc()`
25242526
// 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)
25272529
expect(prevRemoveDataSpy.callCount).toBe(jQuery ? 1 : 2);
25282530

25292531
if (jQuery) {
@@ -2536,6 +2538,6 @@ describe('don\'t leak memory between tests with mocked `$rootScope`', function()
25362538
expect(cleanUpElems[0][0]).toBe(prevOriginalRootElement[0]);
25372539
expect(cleanUpElems[1][0]).toBe(prevRootElement[0]);
25382540
}
2539-
}
2540-
);
2541+
});
2542+
});
25412543
});

0 commit comments

Comments
 (0)