@@ -1692,7 +1692,45 @@ describe('$compile', function() {
1692
1692
element = $compile ( '<div c1 c2><div dep></div></div>' ) ( $rootScope ) ;
1693
1693
expect ( log ) . toEqual ( 'dep:c1-c2' ) ;
1694
1694
} ) ;
1695
+ } ) ;
1696
+
1695
1697
1698
+ it ( 'should instantiate the controller just once when template/templateUrl' , function ( ) {
1699
+ var syncCtrlSpy = jasmine . createSpy ( 'sync controller' ) ,
1700
+ asyncCtrlSpy = jasmine . createSpy ( 'async controller' ) ;
1701
+
1702
+ module ( function ( $compileProvider ) {
1703
+ $compileProvider . directive ( 'myDirectiveSync' , valueFn ( {
1704
+ template : '<div>Hello!</div>' ,
1705
+ controller : syncCtrlSpy
1706
+ } ) ) ;
1707
+ $compileProvider . directive ( 'myDirectiveAsync' , valueFn ( {
1708
+ templateUrl : 'myDirectiveAsync.html' ,
1709
+ controller : asyncCtrlSpy ,
1710
+ compile : function ( ) {
1711
+ return function ( ) {
1712
+ }
1713
+ }
1714
+ } ) ) ;
1715
+ } ) ;
1716
+
1717
+ inject ( function ( $templateCache , $compile , $rootScope ) {
1718
+ expect ( syncCtrlSpy ) . not . toHaveBeenCalled ( ) ;
1719
+ expect ( asyncCtrlSpy ) . not . toHaveBeenCalled ( ) ;
1720
+
1721
+ $templateCache . put ( 'myDirectiveAsync.html' , '<div>Hello!</div>' ) ;
1722
+ element = $compile ( '<div>' +
1723
+ '<span xmy-directive-sync></span>' +
1724
+ '<span my-directive-async></span>' +
1725
+ '</div>' ) ( $rootScope ) ;
1726
+ expect ( syncCtrlSpy ) . not . toHaveBeenCalled ( ) ;
1727
+ expect ( asyncCtrlSpy ) . not . toHaveBeenCalled ( ) ;
1728
+
1729
+ $rootScope . $apply ( ) ;
1730
+
1731
+ //expect(syncCtrlSpy).toHaveBeenCalledOnce();
1732
+ expect ( asyncCtrlSpy ) . toHaveBeenCalledOnce ( ) ;
1733
+ } ) ;
1696
1734
} ) ;
1697
1735
} ) ;
1698
1736
0 commit comments