@@ -56,27 +56,37 @@ describe("widget", function() {
5656
5757
5858 describe ( 'ng:include' , inject ( function ( $rootScope , $compile ) {
59- it ( 'should include on external file' , inject ( function ( $rootScope , $compile , $cacheFactory ) {
59+
60+ function putIntoCache ( url , content ) {
61+ return function ( $templateCache ) {
62+ $templateCache . put ( url , [ 200 , content , { } ] ) ;
63+ } ;
64+ }
65+
66+
67+ it ( 'should include on external file' , inject ( putIntoCache ( 'myUrl' , '{{name}}' ) ,
68+ function ( $rootScope , $compile , $browser ) {
6069 var element = jqLite ( '<ng:include src="url" scope="childScope"></ng:include>' ) ;
6170 var element = $compile ( element ) ( $rootScope ) ;
6271 $rootScope . childScope = $rootScope . $new ( ) ;
6372 $rootScope . childScope . name = 'misko' ;
6473 $rootScope . url = 'myUrl' ;
65- $cacheFactory . get ( 'templates' ) . put ( 'myUrl' , '{{name}}' ) ;
6674 $rootScope . $digest ( ) ;
75+ $browser . defer . flush ( ) ;
6776 expect ( element . text ( ) ) . toEqual ( 'misko' ) ;
6877 } ) ) ;
6978
70-
71- it ( 'should remove previously included text if a falsy value is bound to src' ,
72- inject ( function ( $rootScope , $compile , $cacheFactory ) {
79+
80+ it ( 'should remove previously included text if a falsy value is bound to src' , inject (
81+ putIntoCache ( 'myUrl' , '{{name}}' ) ,
82+ function ( $rootScope , $compile , $browser ) {
7383 var element = jqLite ( '<ng:include src="url" scope="childScope"></ng:include>' ) ;
7484 var element = $compile ( element ) ( $rootScope ) ;
7585 $rootScope . childScope = $rootScope . $new ( ) ;
7686 $rootScope . childScope . name = 'igor' ;
7787 $rootScope . url = 'myUrl' ;
78- $cacheFactory . get ( 'templates' ) . put ( 'myUrl' , '{{name}}' ) ;
7988 $rootScope . $digest ( ) ;
89+ $browser . defer . flush ( ) ;
8090
8191 expect ( element . text ( ) ) . toEqual ( 'igor' ) ;
8292
@@ -86,13 +96,15 @@ describe("widget", function() {
8696 expect ( element . text ( ) ) . toEqual ( '' ) ;
8797 } ) ) ;
8898
89-
90- it ( 'should allow this for scope' , inject ( function ( $rootScope , $compile , $cacheFactory ) {
99+
100+ it ( 'should allow this for scope' , inject ( putIntoCache ( 'myUrl' , '{{"abc"}}' ) ,
101+ function ( $rootScope , $compile , $browser ) {
91102 var element = jqLite ( '<ng:include src="url" scope="this"></ng:include>' ) ;
92103 var element = $compile ( element ) ( $rootScope ) ;
93104 $rootScope . url = 'myUrl' ;
94- $cacheFactory . get ( 'templates' ) . put ( 'myUrl' , '{{"abc"}}' ) ;
95105 $rootScope . $digest ( ) ;
106+ $browser . defer . flush ( ) ;
107+
96108 // TODO(misko): because we are using scope==this, the eval gets registered
97109 // during the flush phase and hence does not get called.
98110 // I don't think passing 'this' makes sense. Does having scope on ng:include makes sense?
@@ -102,39 +114,43 @@ describe("widget", function() {
102114 expect ( element . text ( ) ) . toEqual ( 'abc' ) ;
103115 } ) ) ;
104116
105-
106- it ( 'should evaluate onload expression when a partial is loaded' ,
107- inject ( function ( $rootScope , $compile , $cacheFactory ) {
117+
118+ it ( 'should evaluate onload expression when a partial is loaded' , inject (
119+ putIntoCache ( 'myUrl' , 'my partial' ) ,
120+ function ( $rootScope , $compile , $browser ) {
108121 var element = jqLite ( '<ng:include src="url" onload="loaded = true"></ng:include>' ) ;
109122 var element = $compile ( element ) ( $rootScope ) ;
110123
111124 expect ( $rootScope . loaded ) . not . toBeDefined ( ) ;
112125
113126 $rootScope . url = 'myUrl' ;
114- $cacheFactory . get ( 'templates' ) . put ( 'myUrl' , 'my partial' ) ;
115127 $rootScope . $digest ( ) ;
128+ $browser . defer . flush ( ) ;
129+
116130 expect ( element . text ( ) ) . toEqual ( 'my partial' ) ;
117131 expect ( $rootScope . loaded ) . toBe ( true ) ;
118132 } ) ) ;
119133
120-
121- it ( 'should destroy old scope' , inject ( function ( $rootScope , $compile , $cacheFactory ) {
134+
135+ it ( 'should destroy old scope' , inject ( putIntoCache ( 'myUrl' , 'my partial' ) ,
136+ function ( $rootScope , $compile , $browser ) {
122137 var element = jqLite ( '<ng:include src="url"></ng:include>' ) ;
123138 var element = $compile ( element ) ( $rootScope ) ;
124139
125140 expect ( $rootScope . $$childHead ) . toBeFalsy ( ) ;
126141
127142 $rootScope . url = 'myUrl' ;
128- $cacheFactory . get ( 'templates' ) . put ( 'myUrl' , 'my partial' ) ;
129143 $rootScope . $digest ( ) ;
144+ $browser . defer . flush ( ) ;
130145 expect ( $rootScope . $$childHead ) . toBeTruthy ( ) ;
131146
132147 $rootScope . url = null ;
133148 $rootScope . $digest ( ) ;
134149 expect ( $rootScope . $$childHead ) . toBeFalsy ( ) ;
135150 } ) ) ;
136151
137- it ( 'should do xhr request and cache it' , inject ( function ( $rootScope , $httpBackend , $compile ) {
152+ it ( 'should do xhr request and cache it' ,
153+ inject ( function ( $rootScope , $httpBackend , $compile , $browser ) {
138154 var element = $compile ( '<ng:include src="url"></ng:include>' ) ( $rootScope ) ;
139155 $httpBackend . expect ( 'GET' , 'myUrl' ) . respond ( 'my partial' ) ;
140156
@@ -149,6 +165,7 @@ describe("widget", function() {
149165
150166 $rootScope . url = 'myUrl' ;
151167 $rootScope . $digest ( ) ;
168+ $browser . defer . flush ( ) ;
152169 expect ( element . text ( ) ) . toEqual ( 'my partial' ) ;
153170 dealoc ( $rootScope ) ;
154171 } ) ) ;
@@ -165,11 +182,12 @@ describe("widget", function() {
165182 expect ( element . text ( ) ) . toBe ( '' ) ;
166183 } ) ) ;
167184
168- it ( 'should be async even if served from cache' , inject ( function ( $rootScope , $compile , $cacheFactory ) {
185+ it ( 'should be async even if served from cache' , inject (
186+ putIntoCache ( 'myUrl' , 'my partial' ) ,
187+ function ( $rootScope , $compile , $browser ) {
169188 var element = $compile ( '<ng:include src="url"></ng:include>' ) ( $rootScope ) ;
170189
171190 $rootScope . url = 'myUrl' ;
172- $cacheFactory . get ( 'templates' ) . put ( 'myUrl' , 'my partial' ) ;
173191
174192 var called = 0 ;
175193 // we want to assert only during first watch
@@ -178,6 +196,7 @@ describe("widget", function() {
178196 } ) ;
179197
180198 $rootScope . $digest ( ) ;
199+ $browser . defer . flush ( ) ;
181200 expect ( element . text ( ) ) . toBe ( 'my partial' ) ;
182201 } ) ) ;
183202 } ) ) ;
@@ -574,7 +593,8 @@ describe("widget", function() {
574593 } ) ) ;
575594
576595 it ( 'should initialize view template after the view controller was initialized even when ' +
577- 'templates were cached' , inject ( function ( $rootScope , $compile , $location , $httpBackend , $route ) {
596+ 'templates were cached' ,
597+ inject ( function ( $rootScope , $compile , $location , $httpBackend , $route , $browser ) {
578598 //this is a test for a regression that was introduced by making the ng:view cache sync
579599
580600 $route . when ( '/foo' , { controller : ParentCtrl , template : 'viewPartial.html' } ) ;
@@ -605,6 +625,7 @@ describe("widget", function() {
605625 $rootScope . log = [ ] ;
606626 $location . path ( '/foo' ) ;
607627 $rootScope . $apply ( ) ;
628+ $browser . defer . flush ( ) ;
608629
609630 expect ( $rootScope . log ) . toEqual ( [ 'parent' , 'init' , 'child' ] ) ;
610631 } ) ) ;
@@ -644,9 +665,9 @@ describe("widget", function() {
644665 } ) ) ;
645666
646667 it ( 'should be async even if served from cache' ,
647- inject ( function ( $route , $rootScope , $location , $cacheFactory ) {
668+ inject ( function ( $route , $rootScope , $location , $templateCache , $browser ) {
669+ $templateCache . put ( 'myUrl1' , [ 200 , 'my partial' , { } ] ) ;
648670 $route . when ( '/foo' , { controller : noop , template : 'myUrl1' } ) ;
649- $cacheFactory . get ( 'templates' ) . put ( 'myUrl1' , 'my partial' ) ;
650671 $location . path ( '/foo' ) ;
651672
652673 var called = 0 ;
@@ -656,6 +677,7 @@ describe("widget", function() {
656677 } ) ;
657678
658679 $rootScope . $digest ( ) ;
680+ $browser . defer . flush ( ) ;
659681 expect ( element . text ( ) ) . toBe ( 'my partial' ) ;
660682 } ) ) ;
661683 } ) ;
0 commit comments