Skip to content
Permalink
Browse files

refactor($templateRequest): avoid double calls to $templateCache.put

Closes #10265
  • Loading branch information
pkozlowski-opensource committed Nov 29, 2014
1 parent 96e7897 commit 8c3a42cd684245b08054d9c987db80a399837954
Showing with 15 additions and 9 deletions.
  1. +1 −3 src/ng/templateRequest.js
  2. +14 −6 test/ng/templateRequestSpec.js
@@ -42,10 +42,8 @@ function $TemplateRequestProvider() {

return $http.get(tpl, httpOptions)
.then(function(response) {
var html = response.data;
self.totalPendingRequests--;
$templateCache.put(tpl, html);
return html;
return response.data;
}, handleError);

function handleError(resp) {
@@ -16,16 +16,24 @@ describe('$templateRequest', function() {
expect(content).toBe('<div>abc</div>');
}));

it('should cache the request using $templateCache to prevent extra downloads',
inject(function($rootScope, $templateRequest, $templateCache) {
it('should cache the request to prevent extra downloads',
inject(function($rootScope, $templateRequest, $httpBackend) {

$templateCache.put('tpl.html', 'matias');
$httpBackend.expectGET('tpl.html').respond('matias');

var content;
$templateRequest('tpl.html').then(function(html) { content = html; });
var content = [];
function tplRequestCb(html) {
content.push(html);
}

$templateRequest('tpl.html').then(tplRequestCb);
$httpBackend.flush();

$templateRequest('tpl.html').then(tplRequestCb);
$rootScope.$digest();
expect(content).toBe('matias');

expect(content[0]).toBe('matias');
expect(content[1]).toBe('matias');
}));

it('should throw an error when the template is not found',

0 comments on commit 8c3a42c

Please sign in to comment.
You can’t perform that action at this time.