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

Commit b2a937d

Browse files
test($compile): add test for undefined non-optional reference binding
Demonstrates that #13373 fixes #13367
1 parent 4473b81 commit b2a937d

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
@@ -3964,7 +3964,7 @@ describe('$compile', function() {
39643964
expect(componentScope.ref).toBe('hello world');
39653965

39663966
componentScope.ref = 'ignore me';
3967-
expect($rootScope.$apply).
3967+
expect(function() { $rootScope.$apply(); }).
39683968
toThrowMinErr("$compile", "nonassign", "Expression ''hello ' + name' used with directive 'myComponent' is non-assignable!");
39693969
expect(componentScope.ref).toBe('hello world');
39703970
// reset since the exception was rethrown which prevented phase clearing
@@ -3975,6 +3975,21 @@ describe('$compile', function() {
39753975
expect(componentScope.ref).toBe('hello misko');
39763976
}));
39773977

3978+
it('should complain if assigning to undefined', inject(function() {
3979+
compile('<div><span my-component>');
3980+
$rootScope.$apply();
3981+
expect(componentScope.ref).toBeUndefined();
3982+
3983+
componentScope.ref = 'ignore me';
3984+
expect(function() { $rootScope.$apply(); }).
3985+
toThrowMinErr("$compile", "nonassign", "Expression 'undefined' used with directive 'myComponent' is non-assignable!");
3986+
expect(componentScope.ref).toBeUndefined();
3987+
3988+
$rootScope.$$phase = null; // reset since the exception was rethrown which prevented phase clearing
3989+
$rootScope.$apply();
3990+
expect(componentScope.ref).toBeUndefined();
3991+
}));
3992+
39783993
// regression
39793994
it('should stabilize model', inject(function() {
39803995
compile('<div><span my-component reference="name">');

0 commit comments

Comments
 (0)