@@ -1692,7 +1692,45 @@ describe('$compile', function() {
16921692 element = $compile ( '<div c1 c2><div dep></div></div>' ) ( $rootScope ) ;
16931693 expect ( log ) . toEqual ( 'dep:c1-c2' ) ;
16941694 } ) ;
1695+ } ) ;
1696+
16951697
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+ } ) ;
16961734 } ) ;
16971735 } ) ;
16981736
0 commit comments