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

Commit fd1891d

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

File tree

2 files changed

+52
-45
lines changed

2 files changed

+52
-45
lines changed

test/helpers/testabilityPatch.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,15 @@ function dealoc(obj) {
139139
}
140140

141141
function cleanup(element) {
142-
element.off().removeData();
142+
// element.off().removeData();
143143
if (window.jQuery) {
144144
// jQuery 2.x doesn't expose the cache storage; ensure all element data
145145
// is removed during its cleanup.
146+
console.log(1, element.data());
146147
jQuery.cleanData([element]);
148+
console.log(2, element.data());
149+
jQuery.cleanData(element);
150+
console.log(3, element.data());
147151
}
148152
// Note: We aren't using element.contents() here. Under jQuery, element.contents() can fail
149153
// for IFRAME elements. jQuery explicitly uses (element.contentDocument ||

test/ngMock/angular-mocksSpec.js

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,17 +2417,19 @@ 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+
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() {
24282430
module(function($provide) {
24292431
$provide.decorator('$rootElement', function($delegate) {
2430-
// Spy on `.removeData()` and `jQuery.cleanData()`,
2432+
// Spy on `$rootElement.removeData()` and `jQuery.cleanData()`,
24312433
// so the next test can verify that they have been called as necessary
24322434
prevRootElement = $delegate;
24332435
prevRemoveDataSpy = spyOn($delegate, 'removeData').andCallThrough();
@@ -2444,44 +2446,45 @@ describe('don\'t leak memory between tests', function() {
24442446
inject(function($rootElement) {
24452447
expect($rootElement.injector()).toBeDefined();
24462448
});
2447-
}
2448-
);
2449+
});
24492450

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

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

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+
});
24662469
});
2467-
});
24682470

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

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

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

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

25132517
expect(prevOriginalRemoveDataSpy.callCount).toBe(0);
25142518
});
2515-
}
2516-
);
2519+
});
2520+
25172521

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

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

25292532
if (jQuery) {
@@ -2536,6 +2539,6 @@ describe('don\'t leak memory between tests with mocked `$rootScope`', function()
25362539
expect(cleanUpElems[0][0]).toBe(prevOriginalRootElement[0]);
25372540
expect(cleanUpElems[1][0]).toBe(prevRootElement[0]);
25382541
}
2539-
}
2540-
);
2542+
});
2543+
});
25412544
});

0 commit comments

Comments
 (0)