@@ -991,6 +991,33 @@ describe('$compile', function() {
991
991
}
992
992
} ;
993
993
} ) ;
994
+ $compileProvider . directive ( 'tscope' + uppercase ( name ) , function ( log ) {
995
+ return {
996
+ scope : true ,
997
+ restrict : 'CA' ,
998
+ templateUrl : 'tscope.html' ,
999
+ compile : function ( ) {
1000
+ return function ( scope , element ) {
1001
+ log ( scope . $id ) ;
1002
+ expect ( element . data ( '$scope' ) ) . toBe ( scope ) ;
1003
+ } ;
1004
+ }
1005
+ } ;
1006
+ } ) ;
1007
+ $compileProvider . directive ( 'trscope' + uppercase ( name ) , function ( log ) {
1008
+ return {
1009
+ scope : true ,
1010
+ replace : true ,
1011
+ restrict : 'CA' ,
1012
+ templateUrl : 'trscope.html' ,
1013
+ compile : function ( ) {
1014
+ return function ( scope , element ) {
1015
+ log ( scope . $id ) ;
1016
+ expect ( element . data ( '$scope' ) ) . toBe ( scope ) ;
1017
+ } ;
1018
+ }
1019
+ } ;
1020
+ } ) ;
994
1021
$compileProvider . directive ( 'tiscope' + uppercase ( name ) , function ( log ) {
995
1022
return {
996
1023
scope : { } ,
@@ -1034,6 +1061,33 @@ describe('$compile', function() {
1034
1061
} ) ) ;
1035
1062
1036
1063
1064
+ it ( 'should allow creation of new scopes for directives with templates' , inject (
1065
+ function ( $rootScope , $compile , log , $httpBackend ) {
1066
+ $httpBackend . expect ( 'GET' , 'tscope.html' ) . respond ( '<a log>{{name}}; scopeId: {{$id}}</a>' ) ;
1067
+ element = $compile ( '<div><span tscope></span></div>' ) ( $rootScope ) ;
1068
+ $httpBackend . flush ( ) ;
1069
+ expect ( log ) . toEqual ( 'LOG; log-002-001; 002' ) ;
1070
+ $rootScope . name = 'Jozo' ;
1071
+ $rootScope . $apply ( ) ;
1072
+ expect ( element . text ( ) ) . toBe ( 'Jozo; scopeId: 002' ) ;
1073
+ expect ( element . find ( 'span' ) . scope ( ) . $id ) . toBe ( '002' ) ;
1074
+ } ) ) ;
1075
+
1076
+
1077
+ it ( 'should allow creation of new scopes for replace directives with templates' , inject (
1078
+ function ( $rootScope , $compile , log , $httpBackend ) {
1079
+ $httpBackend . expect ( 'GET' , 'trscope.html' ) .
1080
+ respond ( '<p><a log>{{name}}; scopeId: {{$id}}</a></p>' ) ;
1081
+ element = $compile ( '<div><span trscope></span></div>' ) ( $rootScope ) ;
1082
+ $httpBackend . flush ( ) ;
1083
+ expect ( log ) . toEqual ( 'LOG; log-002-001; 002' ) ;
1084
+ $rootScope . name = 'Jozo' ;
1085
+ $rootScope . $apply ( ) ;
1086
+ expect ( element . text ( ) ) . toBe ( 'Jozo; scopeId: 002' ) ;
1087
+ expect ( element . find ( 'a' ) . scope ( ) . $id ) . toBe ( '002' ) ;
1088
+ } ) ) ;
1089
+
1090
+
1037
1091
it ( 'should allow creation of new isolated scopes for directives with templates' , inject (
1038
1092
function ( $rootScope , $compile , log , $httpBackend ) {
1039
1093
$httpBackend . expect ( 'GET' , 'tiscope.html' ) . respond ( '<a log></a>' ) ;
0 commit comments