@@ -18,11 +18,10 @@ describe('ng-include', function() {
18
18
19
19
it ( 'should include on external file' , inject ( putIntoCache ( 'myUrl' , '{{name}}' ) ,
20
20
function ( $rootScope , $compile ) {
21
- element = jqLite ( '<ng:include src="url" scope="childScope" ></ng:include>' ) ;
21
+ element = jqLite ( '<ng:include src="url"></ng:include>' ) ;
22
22
jqLite ( document . body ) . append ( element ) ;
23
23
element = $compile ( element ) ( $rootScope ) ;
24
- $rootScope . childScope = $rootScope . $new ( ) ;
25
- $rootScope . childScope . name = 'misko' ;
24
+ $rootScope . name = 'misko' ;
26
25
$rootScope . url = 'myUrl' ;
27
26
$rootScope . $digest ( ) ;
28
27
expect ( element . text ( ) ) . toEqual ( 'misko' ) ;
@@ -46,10 +45,9 @@ describe('ng-include', function() {
46
45
it ( 'should remove previously included text if a falsy value is bound to src' , inject (
47
46
putIntoCache ( 'myUrl' , '{{name}}' ) ,
48
47
function ( $rootScope , $compile ) {
49
- element = jqLite ( '<ng:include src="url" scope="childScope" ></ng:include>' ) ;
48
+ element = jqLite ( '<ng:include src="url"></ng:include>' ) ;
50
49
element = $compile ( element ) ( $rootScope ) ;
51
- $rootScope . childScope = $rootScope . $new ( ) ;
52
- $rootScope . childScope . name = 'igor' ;
50
+ $rootScope . name = 'igor' ;
53
51
$rootScope . url = 'myUrl' ;
54
52
$rootScope . $digest ( ) ;
55
53
@@ -62,23 +60,6 @@ describe('ng-include', function() {
62
60
} ) ) ;
63
61
64
62
65
- it ( 'should allow this for scope' , inject ( putIntoCache ( 'myUrl' , '{{"abc"}}' ) ,
66
- function ( $rootScope , $compile ) {
67
- element = jqLite ( '<ng:include src="url" scope="this"></ng:include>' ) ;
68
- element = $compile ( element ) ( $rootScope ) ;
69
- $rootScope . url = 'myUrl' ;
70
- $rootScope . $digest ( ) ;
71
-
72
- // TODO(misko): because we are using scope==this, the eval gets registered
73
- // during the flush phase and hence does not get called.
74
- // I don't think passing 'this' makes sense. Does having scope on ng-include makes sense?
75
- // should we make scope="this" illegal?
76
- $rootScope . $digest ( ) ;
77
-
78
- expect ( element . text ( ) ) . toEqual ( 'abc' ) ;
79
- } ) ) ;
80
-
81
-
82
63
it ( 'should fire $includeContentLoaded event after linking the content' , inject (
83
64
function ( $rootScope , $compile , $templateCache ) {
84
65
var contentLoadedSpy = jasmine . createSpy ( 'content loaded' ) . andCallFake ( function ( ) {
@@ -111,20 +92,33 @@ describe('ng-include', function() {
111
92
} ) ) ;
112
93
113
94
114
- it ( 'should destroy old scope ' , inject ( putIntoCache ( 'myUrl' , 'my partial' ) ,
115
- function ( $rootScope , $compile ) {
116
- element = jqLite ( '<ng:include src=" url"></ng:include> ') ;
117
- element = $compile ( element ) ( $rootScope ) ;
95
+ it ( 'should create child scope and destroy old one ' , inject (
96
+ function ( $rootScope , $compile , $httpBackend ) {
97
+ $httpBackend . whenGET ( 'url1' ) . respond ( 'partial {{$parent. url}} ') ;
98
+ $httpBackend . whenGET ( 'url2' ) . respond ( 404 ) ;
118
99
119
- expect ( $rootScope . $$childHead ) . toBeFalsy ( ) ;
100
+ element = $compile ( '<ng:include src="url"></ng:include>' ) ( $rootScope ) ;
101
+ expect ( element . children ( ) . scope ( ) ) . toBeFalsy ( ) ;
120
102
121
- $rootScope . url = 'myUrl' ;
103
+ $rootScope . url = 'url1' ;
104
+ $rootScope . $digest ( ) ;
105
+ $httpBackend . flush ( ) ;
106
+ expect ( element . children ( ) . scope ( ) ) . toBeTruthy ( ) ;
107
+ expect ( element . text ( ) ) . toBe ( 'partial url1' ) ;
108
+
109
+ $rootScope . url = 'url2' ;
110
+ $rootScope . $digest ( ) ;
111
+ $httpBackend . flush ( ) ;
112
+ expect ( element . children ( ) . scope ( ) ) . toBeFalsy ( ) ;
113
+ expect ( element . text ( ) ) . toBe ( '' ) ;
114
+
115
+ $rootScope . url = 'url1' ;
122
116
$rootScope . $digest ( ) ;
123
- expect ( $rootScope . $$childHead ) . toBeTruthy ( ) ;
117
+ expect ( element . children ( ) . scope ( ) ) . toBeTruthy ( ) ;
124
118
125
119
$rootScope . url = null ;
126
120
$rootScope . $digest ( ) ;
127
- expect ( $rootScope . $$childHead ) . toBeFalsy ( ) ;
121
+ expect ( element . children ( ) . scope ( ) ) . toBeFalsy ( ) ;
128
122
} ) ) ;
129
123
130
124
0 commit comments