Skip to content

Commit 2705085

Browse files
committed
test(ngClass): add some tests about one-time bindings and objects inside arrays
Mostly taken from angular#14404.
1 parent 0409589 commit 2705085

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

test/ng/directive/ngClassSpec.js

+56
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,62 @@ fdescribe('ngClass', function() {
477477
})
478478
);
479479

480+
it('should do value stabilization as expected when one-time binding',
481+
inject(function($rootScope, $compile) {
482+
element = $compile('<div ng-class="::className"></div>')($rootScope);
483+
$rootScope.$digest();
484+
485+
$rootScope.className = 'foo';
486+
$rootScope.$digest();
487+
expect(element).toHaveClass('foo');
488+
489+
$rootScope.className = 'bar';
490+
$rootScope.$digest();
491+
expect(element).toHaveClass('foo');
492+
})
493+
);
494+
495+
it('should remove the watcher when static array one-time binding',
496+
inject(function($rootScope, $compile) {
497+
element = $compile('<div ng-class="::[className]"></div>')($rootScope);
498+
$rootScope.$digest();
499+
500+
$rootScope.$apply('className = "foo"');
501+
expect(element).toHaveClass('foo');
502+
503+
$rootScope.$apply('className = "bar"');
504+
expect(element).toHaveClass('foo');
505+
expect(element).not.toHaveClass('bar');
506+
})
507+
);
508+
509+
it('should do value remove the watcher when static map one-time binding',
510+
inject(function($rootScope, $compile) {
511+
element = $compile('<div ng-class="::{foo: fooPresent}"></div>')($rootScope);
512+
$rootScope.$digest();
513+
514+
$rootScope.fooPresent = true;
515+
$rootScope.$digest();
516+
expect(element).toHaveClass('foo');
517+
518+
$rootScope.fooPresent = false;
519+
$rootScope.$digest();
520+
expect(element).toHaveClass('foo');
521+
})
522+
);
523+
524+
it('should track changes of mutating object inside an array',
525+
inject(function($rootScope, $compile) {
526+
$rootScope.classVar = [{orange: true}];
527+
element = $compile('<div ng-class="classVar"></div>')($rootScope);
528+
$rootScope.$digest();
529+
530+
$rootScope.classVar[0].orange = false;
531+
$rootScope.$digest();
532+
533+
expect(element).not.toHaveClass('orange');
534+
})
535+
);
480536
});
481537

482538
describe('ngClass animations', function() {

0 commit comments

Comments
 (0)