aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorIgor Minar2012-05-02 16:04:11 -0700
committerIgor Minar2012-05-03 00:15:26 -0700
commit843f762c573e38a044f920c5575c6feb46bc7226 (patch)
tree8db63058a0d006fda47acb9ccd42d76a00548e2d /test
parentbeea3a4beda0aaed5fc54af1a992b1c161db7752 (diff)
downloadangular.js-843f762c573e38a044f920c5575c6feb46bc7226.tar.bz2
fix($compile): prevent duplicate directive controller instantiation
Closes #876
Diffstat (limited to 'test')
-rw-r--r--test/ng/compileSpec.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js
index 1aef24fe..54837bf7 100644
--- a/test/ng/compileSpec.js
+++ b/test/ng/compileSpec.js
@@ -1692,7 +1692,45 @@ describe('$compile', function() {
element = $compile('<div c1 c2><div dep></div></div>')($rootScope);
expect(log).toEqual('dep:c1-c2');
});
+ });
+
+ it('should instantiate the controller just once when template/templateUrl', function() {
+ var syncCtrlSpy = jasmine.createSpy('sync controller'),
+ asyncCtrlSpy = jasmine.createSpy('async controller');
+
+ module(function($compileProvider) {
+ $compileProvider.directive('myDirectiveSync', valueFn({
+ template: '<div>Hello!</div>',
+ controller: syncCtrlSpy
+ }));
+ $compileProvider.directive('myDirectiveAsync', valueFn({
+ templateUrl: 'myDirectiveAsync.html',
+ controller: asyncCtrlSpy,
+ compile: function() {
+ return function() {
+ }
+ }
+ }));
+ });
+
+ inject(function($templateCache, $compile, $rootScope) {
+ expect(syncCtrlSpy).not.toHaveBeenCalled();
+ expect(asyncCtrlSpy).not.toHaveBeenCalled();
+
+ $templateCache.put('myDirectiveAsync.html', '<div>Hello!</div>');
+ element = $compile('<div>'+
+ '<span xmy-directive-sync></span>' +
+ '<span my-directive-async></span>' +
+ '</div>')($rootScope);
+ expect(syncCtrlSpy).not.toHaveBeenCalled();
+ expect(asyncCtrlSpy).not.toHaveBeenCalled();
+
+ $rootScope.$apply();
+
+ //expect(syncCtrlSpy).toHaveBeenCalledOnce();
+ expect(asyncCtrlSpy).toHaveBeenCalledOnce();
+ });
});
});