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

Commit 393f68b

Browse files
committed
fixup 1
- Group into a `describe` block - Tweak test descriptions - Fix typos
1 parent 27168af commit 393f68b

File tree

1 file changed

+46
-44
lines changed

1 file changed

+46
-44
lines changed

test/ngMock/angular-mocksSpec.js

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,17 +2413,18 @@ describe('make sure that we can create an injector outside of tests', function()
24132413
});
24142414

24152415

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() {
24242425
module(function($provide) {
24252426
$provide.decorator('$rootElement', function($delegate) {
2426-
// Spy on `.removeData()` and `jQuery.cleanData()`,
2427+
// Spy on `$rootElement.removeData()` and `jQuery.cleanData()`,
24272428
// so the next test can verify that they have been called as necessary
24282429
prevRootElement = $delegate;
24292430
prevRemoveDataSpy = spyOn($delegate, 'removeData').andCallThrough();
@@ -2440,44 +2441,45 @@ describe('don\'t leak memory between tests', function() {
24402441
inject(function($rootElement) {
24412442
expect($rootElement.injector()).toBeDefined();
24422443
});
2443-
}
2444-
);
2444+
});
24452445

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

2453-
if (jQuery) {
2447+
it('should clean up `$rootElement` after each test', function() {
24542448
// One call is made by `testabilityPatch`'s `dealoc()`
24552449
// 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);
24572453

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+
});
24622464
});
2463-
});
24642465

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

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

2480-
// Spy on `.removeData()` and `jQuery.cleanData()`,
2482+
// Spy on `$rootElement.removeData()` and `jQuery.cleanData()`,
24812483
// so the next test can verify that they have been called as necessary
24822484
prevOriginalRootElement = $delegate;
24832485
prevOriginalRemoveDataSpy = spyOn($delegate, 'removeData').andCallThrough();
@@ -2501,25 +2503,25 @@ describe('don\'t leak memory between tests with mocked `$rootScope`', function()
25012503

25022504
// If we don't clean up `prevOriginalRootElement`-related data now, `testabilityPatch` will
25032505
// 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
25062509
prevOriginalRootElement.removeData();
25072510
prevOriginalRemoveDataSpy.reset();
25082511

25092512
expect(prevOriginalRemoveDataSpy.callCount).toBe(0);
25102513
});
2511-
}
2512-
);
2514+
});
2515+
25132516

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

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

25252527
if (jQuery) {
@@ -2532,6 +2534,6 @@ describe('don\'t leak memory between tests with mocked `$rootScope`', function()
25322534
expect(cleanUpElems[0][0]).toBe(prevOriginalRootElement[0]);
25332535
expect(cleanUpElems[1][0]).toBe(prevRootElement[0]);
25342536
}
2535-
}
2536-
);
2537+
});
2538+
});
25372539
});

0 commit comments

Comments
 (0)