aboutsummaryrefslogtreecommitdiffstats
path: root/test/service
diff options
context:
space:
mode:
authorVojta Jina2012-02-15 11:34:56 -0800
committerMisko Hevery2012-02-21 22:46:01 -0800
commit6d0ca95fa05ea6c7bcaef5c1d5a03fa67a6b6d0c (patch)
tree8ebb7303af4783c2a388102680a96d7339a13e51 /test/service
parent3df7b8e57f125160738a811e97ca7819a78c48ff (diff)
downloadangular.js-6d0ca95fa05ea6c7bcaef5c1d5a03fa67a6b6d0c.tar.bz2
feat($compiler): Allow attr.$observe() interpolated attrs
Diffstat (limited to 'test/service')
-rw-r--r--test/service/compilerSpec.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/service/compilerSpec.js b/test/service/compilerSpec.js
index c998765c..9af11f33 100644
--- a/test/service/compilerSpec.js
+++ b/test/service/compilerSpec.js
@@ -1005,6 +1005,19 @@ describe('$compile', function() {
describe('interpolation', function() {
+ var observeSpy, attrValueDuringLinking;
+
+ beforeEach(module(function($compileProvider) {
+ $compileProvider.directive('observer', function() {
+ return function(scope, elm, attr) {
+ observeSpy = jasmine.createSpy('$observe attr');
+
+ attr.$observe('someAttr', observeSpy);
+ attrValueDuringLinking = attr.someAttr;
+ };
+ });
+ }));
+
it('should compile and link both attribute and text bindings', inject(
function($rootScope, $compile) {
@@ -1022,6 +1035,59 @@ describe('$compile', function() {
expect(element.hasClass('ng-binding')).toBe(true);
expect(element.data('$binding')[0].exp).toEqual('{{1+2}}');
}));
+
+
+ it('should observe interpolated attrs', inject(function($rootScope, $compile) {
+ $compile('<div some-attr="{{value}}" observer></div>')($rootScope);
+
+ // should be async
+ expect(observeSpy).not.toHaveBeenCalled();
+
+ $rootScope.$apply(function() {
+ $rootScope.value = 'bound-value';
+ });
+ expect(observeSpy).toHaveBeenCalledOnceWith('bound-value');
+ }));
+
+
+ it('should set interpolated attrs to undefined', inject(function($rootScope, $compile) {
+ attrValueDuringLinking = null;
+ $compile('<div some-attr="{{whatever}}" observer></div>')($rootScope);
+ expect(attrValueDuringLinking).toBeUndefined();
+ }));
+
+
+ it('should not call observer of non-interpolated attr', inject(function($rootScope, $compile) {
+ $compile('<div some-attr="nonBound" observer></div>')($rootScope);
+ expect(attrValueDuringLinking).toBe('nonBound');
+
+ $rootScope.$digest();
+ expect(observeSpy).not.toHaveBeenCalled();
+ }));
+
+
+ it('should delegate exceptions to $exceptionHandler', function() {
+ observeSpy = jasmine.createSpy('$observe attr').andThrow('ERROR');
+
+ module(function($compileProvider, $exceptionHandlerProvider) {
+ $exceptionHandlerProvider.mode('log');
+ $compileProvider.directive('error', function() {
+ return function(scope, elm, attr) {
+ attr.$observe('someAttr', observeSpy);
+ attr.$observe('someAttr', observeSpy);
+ };
+ });
+ });
+
+ inject(function($compile, $rootScope, $exceptionHandler) {
+ $compile('<div some-attr="{{value}}" error></div>')($rootScope);
+ $rootScope.$digest();
+
+ expect(observeSpy).toHaveBeenCalled();
+ expect(observeSpy.callCount).toBe(2);
+ expect($exceptionHandler.errors).toEqual(['ERROR', 'ERROR']);
+ });
+ })
});