2012-03-08 23:00:38 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
describe('scriptDirective', function() {
|
|
|
|
|
var element;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
afterEach(function(){
|
|
|
|
|
dealoc(element);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should populate $templateCache with contents of a ng-template script element', inject(
|
|
|
|
|
function($compile, $templateCache) {
|
|
|
|
|
$compile('<div>foo' +
|
|
|
|
|
'<script id="/ignore">ignore me</script>' +
|
|
|
|
|
'<script type="text/ng-template" id="/myTemplate.html"><x>{{y}}</x></script>' +
|
|
|
|
|
'</div>' );
|
|
|
|
|
expect($templateCache.get('/myTemplate.html')).toBe('<x>{{y}}</x>');
|
|
|
|
|
expect($templateCache.get('/ignore')).toBeUndefined();
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should not compile scripts', inject(function($compile, $templateCache, $rootScope) {
|
|
|
|
|
var doc = jqLite('<div></div>');
|
2012-04-17 20:55:10 +00:00
|
|
|
// jQuery is too smart and removes script tags
|
|
|
|
|
doc[0].innerHTML = 'foo' +
|
|
|
|
|
'<script type="text/javascript">some {{binding}}</script>' +
|
|
|
|
|
'<script type="text/ng-template" id="/some">other {{binding}}</script>';
|
2012-03-08 23:00:38 +00:00
|
|
|
|
|
|
|
|
$compile(doc)($rootScope);
|
|
|
|
|
$rootScope.$digest();
|
|
|
|
|
|
|
|
|
|
var scripts = doc.find('script');
|
2012-04-17 20:55:10 +00:00
|
|
|
expect(scripts.eq(0)[0].text).toBe('some {{binding}}');
|
|
|
|
|
expect(scripts.eq(1)[0].text).toBe('other {{binding}}');
|
2012-03-08 23:00:38 +00:00
|
|
|
dealoc(doc);
|
|
|
|
|
}));
|
|
|
|
|
});
|