From 45c5688d42154be8582b2ecab0cc4e14cccfc27b Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Wed, 25 Nov 2015 10:48:41 +0000 Subject: [PATCH] test($compile): add test for undefined non-optional reference binding Demonstrates that #13373 fixes #13367 --- test/ng/compileSpec.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index efd0f25f7cf8..44b3bfd08bc5 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -3953,7 +3953,7 @@ describe('$compile', function() { expect(componentScope.ref).toBe('hello world'); componentScope.ref = 'ignore me'; - expect($rootScope.$apply). + expect(function() { $rootScope.$apply(); }). toThrowMinErr("$compile", "nonassign", "Expression ''hello ' + name' used with directive 'myComponent' is non-assignable!"); expect(componentScope.ref).toBe('hello world'); // reset since the exception was rethrown which prevented phase clearing @@ -3964,6 +3964,21 @@ describe('$compile', function() { expect(componentScope.ref).toBe('hello misko'); })); + it('should complain if assigning to undefined', inject(function() { + compile('
'); + $rootScope.$apply(); + expect(componentScope.ref).toBeUndefined(); + + componentScope.ref = 'ignore me'; + expect(function() { $rootScope.$apply(); }). + toThrowMinErr("$compile", "nonassign", "Expression 'undefined' used with directive 'myComponent' is non-assignable!"); + expect(componentScope.ref).toBeUndefined(); + + $rootScope.$$phase = null; // reset since the exception was rethrown which prevented phase clearing + $rootScope.$apply(); + expect(componentScope.ref).toBeUndefined(); + })); + // regression it('should stabilize model', inject(function() { compile('
');