@@ -95,6 +95,34 @@ export function runCompilerCommonTests() {
95
95
} ) ;
96
96
} ) ) ;
97
97
98
+ it ( 'should not modify the cached url template' , inject ( [ AsyncTestCompleter ] , ( async ) => {
99
+ var urlData = MapWrapper . createFromStringMap ( {
100
+ 'someUrl' : '<div>a</div>'
101
+ } ) ;
102
+ var log = [ ] ;
103
+ var logAndModifyCompileStep = ( parent , current , control ) => {
104
+ var tagName = DOM . tagName ( current . element ) . toUpperCase ( ) ;
105
+ if ( tagName == 'DIV' ) {
106
+ ListWrapper . push ( log , DOM . getInnerHTML ( current . element ) ) ;
107
+ DOM . setInnerHTML ( current . element , '' ) ;
108
+ }
109
+ } ;
110
+ var compiler = createCompiler ( logAndModifyCompileStep , urlData ) ;
111
+ PromiseWrapper . all ( [
112
+ compiler . compile ( new ViewDefinition ( {
113
+ componentId : 'someId' ,
114
+ absUrl : 'someUrl'
115
+ } ) ) ,
116
+ compiler . compile ( new ViewDefinition ( {
117
+ componentId : 'someId' ,
118
+ absUrl : 'someUrl'
119
+ } ) )
120
+ ] ) . then ( ( _ ) => {
121
+ expect ( log ) . toEqual ( [ 'a' , 'a' ] ) ;
122
+ async . done ( ) ;
123
+ } ) ;
124
+ } ) ) ;
125
+
98
126
it ( 'should report loading errors' , inject ( [ AsyncTestCompleter ] , ( async ) => {
99
127
var compiler = createCompiler ( EMPTY_STEP , MapWrapper . create ( ) ) ;
100
128
PromiseWrapper . catchError ( compiler . compile ( new ViewDefinition ( {
@@ -172,10 +200,15 @@ var EMPTY_STEP = (parent, current, control) => {
172
200
} ;
173
201
174
202
class FakeTemplateLoader extends TemplateLoader {
175
- _urlData : Map < string , string > ;
203
+ _urlData : Map < string , any > ;
176
204
constructor ( urlData ) {
177
205
super ( null , new UrlResolver ( ) ) ;
178
- this . _urlData = urlData ;
206
+ this . _urlData = MapWrapper . create ( ) ;
207
+ // Important: create the template elements only once,
208
+ // as this is the behavior of the real template loader.
209
+ MapWrapper . forEach ( urlData , ( content , url ) => {
210
+ MapWrapper . set ( this . _urlData , url , DOM . createTemplate ( content ) ) ;
211
+ } ) ;
179
212
}
180
213
181
214
load ( template : ViewDefinition ) {
@@ -186,7 +219,7 @@ class FakeTemplateLoader extends TemplateLoader {
186
219
if ( isPresent ( template . absUrl ) ) {
187
220
var content = MapWrapper . get ( this . _urlData , template . absUrl ) ;
188
221
if ( isPresent ( content ) ) {
189
- return PromiseWrapper . resolve ( DOM . createTemplate ( content ) ) ;
222
+ return PromiseWrapper . resolve ( content ) ;
190
223
}
191
224
}
192
225
0 commit comments