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

Commit 45c5688

Browse files
test($compile): add test for undefined non-optional reference binding
Demonstrates that #13373 fixes #13367
1 parent 7bb2414 commit 45c5688

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

test/ng/compileSpec.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -3953,7 +3953,7 @@ describe('$compile', function() {
39533953
expect(componentScope.ref).toBe('hello world');
39543954

39553955
componentScope.ref = 'ignore me';
3956-
expect($rootScope.$apply).
3956+
expect(function() { $rootScope.$apply(); }).
39573957
toThrowMinErr("$compile", "nonassign", "Expression ''hello ' + name' used with directive 'myComponent' is non-assignable!");
39583958
expect(componentScope.ref).toBe('hello world');
39593959
// reset since the exception was rethrown which prevented phase clearing
@@ -3964,6 +3964,21 @@ describe('$compile', function() {
39643964
expect(componentScope.ref).toBe('hello misko');
39653965
}));
39663966

3967+
it('should complain if assigning to undefined', inject(function() {
3968+
compile('<div><span my-component>');
3969+
$rootScope.$apply();
3970+
expect(componentScope.ref).toBeUndefined();
3971+
3972+
componentScope.ref = 'ignore me';
3973+
expect(function() { $rootScope.$apply(); }).
3974+
toThrowMinErr("$compile", "nonassign", "Expression 'undefined' used with directive 'myComponent' is non-assignable!");
3975+
expect(componentScope.ref).toBeUndefined();
3976+
3977+
$rootScope.$$phase = null; // reset since the exception was rethrown which prevented phase clearing
3978+
$rootScope.$apply();
3979+
expect(componentScope.ref).toBeUndefined();
3980+
}));
3981+
39673982
// regression
39683983
it('should stabilize model', inject(function() {
39693984
compile('<div><span my-component reference="name">');

0 commit comments

Comments
 (0)