Skip to content

Commit ea817d7

Browse files
committed
WIP: fix regression pointed out by @lgalfaso
1 parent b41118f commit ea817d7

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/ng/rootScope.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ function $RootScopeProvider(){
756756

757757
// prevent NPEs since these methods have references to properties we nulled out
758758
this.$destroy = this.$digest = this.$apply = noop;
759+
this.$on = this.$watch = function() { return noop; };
759760

760761

761762
/* jshint -W103 */

test/ng/rootScopeSpec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,28 @@ describe('Scope', function() {
876876
$rootScope.$broadcast(EVENT);
877877
expect(spy.callCount).toBe(1);
878878
}));
879+
880+
881+
it("should do nothing when a child event listener is registered after parent's destruction",
882+
inject(function($rootScope) {
883+
var parent = $rootScope.$new(),
884+
child = parent.$new();
885+
886+
parent.$destroy();
887+
var fn = child.$on('someEvent', function() {});
888+
expect(fn).toBe(noop);
889+
}));
890+
891+
892+
it("should do nothing when a child watch is registered after parent's destruction",
893+
inject(function($rootScope) {
894+
var parent = $rootScope.$new(),
895+
child = parent.$new();
896+
897+
parent.$destroy();
898+
var fn = child.$watch('somePath', function() {});
899+
expect(fn).toBe(noop);
900+
}));
879901
});
880902

881903

0 commit comments

Comments
 (0)