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

Commit 91834bc

Browse files
test($compile): use ngMock.Scope.$countChildScopes()
1 parent 841c090 commit 91834bc

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

test/ng/compileSpec.js

+24-30
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ describe('$compile', function() {
2626
return !!d.toString().match(/SVGForeignObject/);
2727
}
2828

29-
function countScopes($rootScope) {
30-
return [$rootScope].concat(
31-
getChildScopes($rootScope)
32-
).length;
33-
}
34-
3529
function getChildScopes(scope) {
3630
var children = [];
3731
if (!scope.$$childHead) { return children; }
@@ -5264,19 +5258,19 @@ describe('$compile', function() {
52645258
'</div>')($rootScope);
52655259

52665260
$rootScope.$apply('t = false');
5267-
expect(countScopes($rootScope)).toBe(2);
5261+
expect($rootScope.$countChildScopes()).toBe(1);
52685262
expect(element.text()).toBe('');
52695263

52705264
$rootScope.$apply('t = true');
5271-
expect(countScopes($rootScope)).toBe(5);
5265+
expect($rootScope.$countChildScopes()).toBe(4);
52725266
expect(element.text()).toBe('Success');
52735267

52745268
$rootScope.$apply('t = false');
5275-
expect(countScopes($rootScope)).toBe(2);
5269+
expect($rootScope.$countChildScopes()).toBe(1);
52765270
expect(element.text()).toBe('');
52775271

52785272
$rootScope.$apply('t = true');
5279-
expect(countScopes($rootScope)).toBe(5);
5273+
expect($rootScope.$countChildScopes()).toBe(4);
52805274
expect(element.text()).toBe('Success');
52815275
});
52825276
});
@@ -5301,19 +5295,19 @@ describe('$compile', function() {
53015295
'</div>')($rootScope);
53025296

53035297
$rootScope.$apply('t = false');
5304-
expect(countScopes($rootScope)).toBe(2);
5298+
expect($rootScope.$countChildScopes()).toBe(1);
53055299
expect(element.text()).toBe('');
53065300

53075301
$rootScope.$apply('t = true');
5308-
expect(countScopes($rootScope)).toBe(5);
5302+
expect($rootScope.$countChildScopes()).toBe(4);
53095303
expect(element.text()).toBe('Success');
53105304

53115305
$rootScope.$apply('t = false');
5312-
expect(countScopes($rootScope)).toBe(2);
5306+
expect($rootScope.$countChildScopes()).toBe(1);
53135307
expect(element.text()).toBe('');
53145308

53155309
$rootScope.$apply('t = true');
5316-
expect(countScopes($rootScope)).toBe(5);
5310+
expect($rootScope.$countChildScopes()).toBe(4);
53175311
expect(element.text()).toBe('Success');
53185312
});
53195313
});
@@ -5345,22 +5339,22 @@ describe('$compile', function() {
53455339
$rootScope.$apply('t = true');
53465340
expect(element.text()).toContain('msg-1');
53475341
// Expected scopes: $rootScope, ngIf, transclusion, ngRepeat
5348-
expect(countScopes($rootScope)).toEqual(4);
5342+
expect($rootScope.$countChildScopes()).toBe(3);
53495343

53505344
$rootScope.$apply('t = false');
53515345
expect(element.text()).not.toContain('msg-1');
53525346
// Expected scopes: $rootScope
5353-
expect(countScopes($rootScope)).toEqual(1);
5347+
expect($rootScope.$countChildScopes()).toBe(0);
53545348

53555349
$rootScope.$apply('t = true');
53565350
expect(element.text()).toContain('msg-1');
53575351
// Expected scopes: $rootScope, ngIf, transclusion, ngRepeat
5358-
expect(countScopes($rootScope)).toEqual(4);
5352+
expect($rootScope.$countChildScopes()).toBe(3);
53595353

53605354
$rootScope.$apply('t = false');
53615355
expect(element.text()).not.toContain('msg-1');
53625356
// Expected scopes: $rootScope
5363-
expect(countScopes($rootScope)).toEqual(1);
5357+
expect($rootScope.$countChildScopes()).toBe(0);
53645358
}));
53655359

53665360

@@ -5377,22 +5371,22 @@ describe('$compile', function() {
53775371
$rootScope.$apply('t = true');
53785372
expect(element.text()).toContain('msg-1msg-1');
53795373
// Expected scopes: $rootScope, ngIf, transclusion, ngRepeat
5380-
expect(countScopes($rootScope)).toEqual(4);
5374+
expect($rootScope.$countChildScopes()).toBe(3);
53815375

53825376
$rootScope.$apply('t = false');
53835377
expect(element.text()).not.toContain('msg-1msg-1');
53845378
// Expected scopes: $rootScope
5385-
expect(countScopes($rootScope)).toEqual(1);
5379+
expect($rootScope.$countChildScopes()).toBe(0);
53865380

53875381
$rootScope.$apply('t = true');
53885382
expect(element.text()).toContain('msg-1msg-1');
53895383
// Expected scopes: $rootScope, ngIf, transclusion, ngRepeat
5390-
expect(countScopes($rootScope)).toEqual(4);
5384+
expect($rootScope.$countChildScopes()).toBe(3);
53915385

53925386
$rootScope.$apply('t = false');
53935387
expect(element.text()).not.toContain('msg-1msg-1');
53945388
// Expected scopes: $rootScope
5395-
expect(countScopes($rootScope)).toEqual(1);
5389+
expect($rootScope.$countChildScopes()).toBe(0);
53965390
}));
53975391

53985392

@@ -5408,22 +5402,22 @@ describe('$compile', function() {
54085402
$rootScope.$apply('t = true');
54095403
expect(element.html()).toContain('some comment');
54105404
// Expected scopes: $rootScope, ngIf, transclusion
5411-
expect(countScopes($rootScope)).toEqual(3);
5405+
expect($rootScope.$countChildScopes()).toBe(2);
54125406

54135407
$rootScope.$apply('t = false');
54145408
expect(element.html()).not.toContain('some comment');
54155409
// Expected scopes: $rootScope
5416-
expect(countScopes($rootScope)).toEqual(1);
5410+
expect($rootScope.$countChildScopes()).toBe(0);
54175411

54185412
$rootScope.$apply('t = true');
54195413
expect(element.html()).toContain('some comment');
54205414
// Expected scopes: $rootScope, ngIf, transclusion
5421-
expect(countScopes($rootScope)).toEqual(3);
5415+
expect($rootScope.$countChildScopes()).toBe(2);
54225416

54235417
$rootScope.$apply('t = false');
54245418
expect(element.html()).not.toContain('some comment');
54255419
// Expected scopes: $rootScope
5426-
expect(countScopes($rootScope)).toEqual(1);
5420+
expect($rootScope.$countChildScopes()).toBe(0);
54275421
}));
54285422

54295423
it('should not leak the transclude scope if the transcluded contains only text nodes',
@@ -5438,22 +5432,22 @@ describe('$compile', function() {
54385432
$rootScope.$apply('t = true');
54395433
expect(element.html()).toContain('some text');
54405434
// Expected scopes: $rootScope, ngIf, transclusion
5441-
expect(countScopes($rootScope)).toEqual(3);
5435+
expect($rootScope.$countChildScopes()).toBe(2);
54425436

54435437
$rootScope.$apply('t = false');
54445438
expect(element.html()).not.toContain('some text');
54455439
// Expected scopes: $rootScope
5446-
expect(countScopes($rootScope)).toEqual(1);
5440+
expect($rootScope.$countChildScopes()).toBe(0);
54475441

54485442
$rootScope.$apply('t = true');
54495443
expect(element.html()).toContain('some text');
54505444
// Expected scopes: $rootScope, ngIf, transclusion
5451-
expect(countScopes($rootScope)).toEqual(3);
5445+
expect($rootScope.$countChildScopes()).toBe(2);
54525446

54535447
$rootScope.$apply('t = false');
54545448
expect(element.html()).not.toContain('some text');
54555449
// Expected scopes: $rootScope
5456-
expect(countScopes($rootScope)).toEqual(1);
5450+
expect($rootScope.$countChildScopes()).toBe(0);
54575451
}));
54585452

54595453
it('should mark as destroyed all sub scopes of the scope being destroyed',

0 commit comments

Comments
 (0)