From 9be82d942fc6ab2772197c84a35a4c374c604cbc Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 4 Jun 2012 15:06:02 -0700 Subject: refactor($compile): always call attr.$observe attr.$observe used to call function only if there was interpolation on that attribute. We now call the observation function all the time but we only save the reference to it if interpolation is present. --- test/ng/compileSpec.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index a6a81a0e..655d48cc 100644 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -1249,15 +1249,15 @@ describe('$compile', function() { describe('interpolation', function() { - var observeSpy, attrValueDuringLinking; + var observeSpy, directiveAttrs; beforeEach(module(function() { directive('observer', function() { return function(scope, elm, attr) { + directiveAttrs = attr; observeSpy = jasmine.createSpy('$observe attr'); expect(attr.$observe('someAttr', observeSpy)).toBe(observeSpy); - attrValueDuringLinking = attr.someAttr; }; }); })); @@ -1295,19 +1295,21 @@ describe('$compile', function() { it('should set interpolated attrs to undefined', inject(function($rootScope, $compile) { - attrValueDuringLinking = null; $compile('
')($rootScope); - expect(attrValueDuringLinking).toBeUndefined(); + expect(directiveAttrs.someAttr).toBeUndefined(); })); - it('should not call observer of non-interpolated attr', inject(function($rootScope, $compile) { - $compile('
')($rootScope); - expect(attrValueDuringLinking).toBe('nonBound'); + it('should call observer of non-interpolated attr through $evalAsync', + inject(function($rootScope, $compile) { + $compile('
')($rootScope); + expect(directiveAttrs.someAttr).toBe('nonBound'); - $rootScope.$digest(); - expect(observeSpy).not.toHaveBeenCalled(); - })); + expect(observeSpy).not.toHaveBeenCalled(); + $rootScope.$digest(); + expect(observeSpy).toHaveBeenCalled(); + }) + ); it('should delegate exceptions to $exceptionHandler', function() { -- cgit v1.2.3