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

Commit dc57ef2

Browse files
committed
fixup! simplify tests
1 parent 696b7a4 commit dc57ef2

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

test/ng/directive/ngSwitchSpec.js

+6-23
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('ngSwitch', function() {
3636
}));
3737

3838

39-
it('should show all switch-whens that match the current value', inject(function($rootScope, $compile, $$rAF) {
39+
it('should show all switch-whens that match the current value', inject(function($rootScope, $compile) {
4040
element = $compile(
4141
'<ul ng-switch="select">' +
4242
'<li ng-switch-when="1">first:{{name}}</li>' +
@@ -57,15 +57,13 @@ describe('ngSwitch', function() {
5757

5858
$rootScope.select = 2;
5959
$rootScope.$apply();
60-
$$rAF.flush();
6160
expect(element.text()).toEqual('second:shyam');
6261
$rootScope.name = 'misko';
6362
$rootScope.$apply();
6463
expect(element.text()).toEqual('second:misko');
6564

6665
$rootScope.select = true;
6766
$rootScope.$apply();
68-
$$rAF.flush();
6967
expect(element.text()).toEqual('true:misko');
7068
}));
7169

@@ -282,7 +280,7 @@ describe('ngSwitch', function() {
282280
}));
283281

284282

285-
it('should properly support case labels with different numbers of transclude fns', inject(function($rootScope, $compile, $$rAF) {
283+
it('should properly support case labels with different numbers of transclude fns', inject(function($rootScope, $compile) {
286284
element = $compile(
287285
'<div ng-switch="mode">' +
288286
'<p ng-switch-when="a">Block1</p>' +
@@ -296,11 +294,9 @@ describe('ngSwitch', function() {
296294

297295
$rootScope.$apply('mode = "b"');
298296
expect(element.children().length).toBe(1);
299-
$$rAF.flush();
300297

301298
$rootScope.$apply('mode = "a"');
302299
expect(element.children().length).toBe(2);
303-
$$rAF.flush();
304300

305301
$rootScope.$apply('mode = "b"');
306302
expect(element.children().length).toBe(1);
@@ -324,7 +320,9 @@ describe('ngSwitch', function() {
324320
$rootScope.$apply();
325321
spy.calls.reset();
326322
expect(element.text()).toEqual('second');
327-
// The animation completion is async even without actual animations
323+
// If ngSwitch re-introduces code that triggers a digest after an element is removed (in an
324+
// animation .then callback), flushing the queue ensures the callback will be called, and the test
325+
// fails
328326
$$rAF.flush();
329327

330328
expect(spy).not.toHaveBeenCalled();
@@ -334,7 +332,7 @@ describe('ngSwitch', function() {
334332

335333

336334
it('should handle changes to the switch value in a digest loop with multiple value matches',
337-
inject(function($$rAF, $compile, $rootScope, $timeout) {
335+
inject(function($compile, $rootScope) {
338336
var scope = $rootScope.$new();
339337
scope.value = 'foo';
340338

@@ -364,11 +362,6 @@ describe('ngSwitch', function() {
364362

365363

366364
describe('ngSwitchWhen separator', function() {
367-
var $$rAF;
368-
369-
beforeEach(inject(function(_$$rAF_) {
370-
$$rAF = _$$rAF_;
371-
}));
372365

373366
it('should be possible to define a separator', inject(function($rootScope, $compile) {
374367
element = $compile(
@@ -383,12 +376,10 @@ describe('ngSwitch', function() {
383376
expect(element.children().length).toBe(2);
384377
expect(element.text()).toBe('Block1|Block2|');
385378
$rootScope.$apply('mode = "b"');
386-
$$rAF.flush();
387379

388380
expect(element.children().length).toBe(1);
389381
expect(element.text()).toBe('Block1|');
390382
$rootScope.$apply('mode = "c"');
391-
$$rAF.flush();
392383

393384
expect(element.children().length).toBe(1);
394385
expect(element.text()).toBe('Block3|');
@@ -408,12 +399,10 @@ describe('ngSwitch', function() {
408399
expect(element.children().length).toBe(2);
409400
expect(element.text()).toBe('Block1|Block2|');
410401
$rootScope.$apply('mode = ""');
411-
$$rAF.flush();
412402

413403
expect(element.children().length).toBe(1);
414404
expect(element.text()).toBe('Block1|');
415405
$rootScope.$apply('mode = "c"');
416-
$$rAF.flush();
417406

418407
expect(element.children().length).toBe(1);
419408
expect(element.text()).toBe('Block3|');
@@ -433,12 +422,10 @@ describe('ngSwitch', function() {
433422
expect(element.children().length).toBe(2);
434423
expect(element.text()).toBe('Block1|Block2|');
435424
$rootScope.$apply('mode = "b"');
436-
$$rAF.flush();
437425

438426
expect(element.children().length).toBe(1);
439427
expect(element.text()).toBe('Block1|');
440428
$rootScope.$apply('mode = "c"');
441-
$$rAF.flush();
442429

443430
expect(element.children().length).toBe(1);
444431
expect(element.text()).toBe('Block3|');
@@ -458,12 +445,10 @@ describe('ngSwitch', function() {
458445
expect(element.children().length).toBe(2);
459446
expect(element.text()).toBe('Block1|Block2|');
460447
$rootScope.$apply('mode = "b|a"');
461-
$$rAF.flush();
462448

463449
expect(element.children().length).toBe(1);
464450
expect(element.text()).toBe('Block1|');
465451
$rootScope.$apply('mode = "c"');
466-
$$rAF.flush();
467452

468453
expect(element.children().length).toBe(1);
469454
expect(element.text()).toBe('Block3|');
@@ -483,12 +468,10 @@ describe('ngSwitch', function() {
483468
expect(element.children().length).toBe(2);
484469
expect(element.text()).toBe('Block1|Block2|');
485470
$rootScope.$apply('mode = "b"');
486-
$$rAF.flush();
487471

488472
expect(element.children().length).toBe(1);
489473
expect(element.text()).toBe('Block1|');
490474
$rootScope.$apply('mode = "c"');
491-
$$rAF.flush();
492475

493476
expect(element.children().length).toBe(1);
494477
expect(element.text()).toBe('Block3|');

0 commit comments

Comments
 (0)