| OLD | NEW |
| 1 library ng_template_spec; | 1 library ng_template_spec; |
| 2 | 2 |
| 3 import '../_specs.dart'; | 3 import '../_specs.dart'; |
| 4 | 4 |
| 5 main() { | 5 main() { |
| 6 describe('NgTemplateDirective', () { | 6 describe('NgTemplateDirective', () { |
| 7 TestBed _; | 7 TestBed _; |
| 8 var element; | 8 var element; |
| 9 | 9 |
| 10 beforeEach((TestBed tb) => _ = tb); | |
| 11 | |
| 12 they(should, htmlForElements, callback) { | 10 they(should, htmlForElements, callback) { |
| 13 htmlForElements.forEach((html) { | 11 htmlForElements.forEach((html) { |
| 14 var tagName = html.contains('<template') ? 'template' : 'script'; | 12 var tagName = html.contains('<template') ? 'template' : 'script'; |
| 15 describe('$tagName[type="text/ng-template"]', () { | 13 describe('$tagName[type="text/ng-template"]', () { |
| 16 beforeEach(() => element = e(html)); | 14 beforeEach(inject((TestBed tb) => _ = tb)); |
| 17 it(should, callback); | 15 it(should, () { |
| 16 element = $(html); |
| 17 inject(callback); |
| 18 }); |
| 18 }); | 19 }); |
| 19 }); | 20 }); |
| 20 } | 21 } |
| 21 | 22 |
| 22 they('should populate TemplateCache with contents of a ng-template template
element', | 23 they('should populate TemplateCache with contents of a ng-template template
element', |
| 23 [ // <template> | 24 [ // <template> |
| 24 '<div>foo' + | 25 '<div>foo' + |
| 25 '<template id="/ignore">ignore me</template>' + | 26 '<template id="/ignore">ignore me</template>' + |
| 26 '<template type="text/ng-template" id="/myTemplate.html"><x>{{y}}</x><
/template>' + | 27 '<template type="text/ng-template" id="/myTemplate.html"><x>{{y}}</x><
/template>' + |
| 27 '</div>', | 28 '</div>', |
| 28 // <script> | 29 // <script> |
| 29 '<div>foo' + | 30 '<div>foo' + |
| 30 '<script id="/ignore">ignore me</script>' + | 31 '<script id="/ignore">ignore me</script>' + |
| 31 '<script type="text/ng-template" id="/myTemplate.html"><x>{{y}}</x></s
cript>' + | 32 '<script type="text/ng-template" id="/myTemplate.html"><x>{{y}}</x></s
cript>' + |
| 32 '</div>'], | 33 '</div>'], |
| 33 (TemplateCache templateCache) { | 34 (Injector injector, Compiler compiler, TemplateCache templateCache, Direct
iveMap directives) { |
| 34 _.compile(element); | 35 compiler(element, directives)(injector, element); |
| 35 expect(templateCache.get('/ignore')).toBeNull(); | 36 expect(templateCache.get('/ignore')).toBeNull(); |
| 36 expect(templateCache.get('/myTemplate.html').responseText).toEqual('<x>{
{y}}</x>'); | 37 expect(templateCache.get('/myTemplate.html').responseText).toEqual('<x>{
{y}}</x>'); |
| 37 } | 38 } |
| 38 ); | 39 ); |
| 39 | 40 |
| 40 it('should not compile template elements', () { | 41 they('should not compile template elements', |
| 41 _.compile(element = e('<div>foo' | 42 [ // <template> |
| 42 '<template type="text/javascript">some {{binding}} <div></div></templa
te>' | 43 '<div>foo' + |
| 43 '<template type="text/ng-template" id="/some">other {{binding}} <div><
/div></template>' | 44 '<template type="text/javascript">some {{binding}} <div></div></templa
te>' + |
| 44 '</div>')); | 45 '<template type="text/ng-template" id="/some">other {{binding}} <div><
/div></template>' + |
| 46 '</div>', |
| 47 // <script> |
| 48 '<div>foo' + |
| 49 '<script type="text/javascript">some {{binding}} <div></div></script>'
+ |
| 50 '<script type="text/ng-template" id="/some">other {{binding}} <div></d
iv></script>' + |
| 51 '</div>'], |
| 52 (Injector injector, Compiler compiler, TemplateCache templateCache, Scope
scope, DirectiveMap directives) { |
| 53 var templates = element.contents(); |
| 54 compiler(element, directives)(injector, element); |
| 45 | 55 |
| 46 microLeap(); | 56 microLeap(); |
| 47 | 57 // This binding should have been left alone (i.e. not interpolated). |
| 48 expect(element.children[1] is TemplateElement).toBeTruthy(); | 58 expect(templates[2].innerHtml).toEqual('other {{binding}} <div></div>'); |
| 49 // This binding should have been left alone (i.e. not interpolated). | 59 } |
| 50 expect(element.children[1].content).toHaveHtml('other {{binding}} <div></d
iv>'); | 60 ); |
| 51 }); | |
| 52 | |
| 53 it('should not compile script elements', () { | |
| 54 _.compile(element = e('<div>foo' | |
| 55 '<script type="text/javascript">some {{binding}} <div></div></script>' | |
| 56 '<script type="text/ng-template" id="/some">other {{binding}} <div></d
iv></script>' | |
| 57 '</div>')); | |
| 58 | |
| 59 microLeap(); | |
| 60 | |
| 61 // This binding should have been left alone (i.e. not interpolated). | |
| 62 expect(element.children[1]).toHaveHtml('other {{binding}} <div></div>'); | |
| 63 }); | |
| 64 }); | 61 }); |
| 65 } | 62 } |
| OLD | NEW |