jeudi 28 août 2014

Testing with $httpBackend and angular-translate directive


Vote count:

0




I am expending a lot of time trying to understand how the $httpBackend and the angular-translate could work together in order to test if the translation functionality still works.


I am in this point, and I really don't know how to solve this problem.



'use strict';

describe('Directive: translate', function () {

beforeEach(function () {
angular.module('myApp', ['pascalprecht.translate']);
});

var element,
$compile,
$rootScope,
$http,
$httpBackend;

beforeEach(inject(function (_$rootScope_, _$compile_, _$httpBackend_, _$http_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
$http = _$http_;
$httpBackend = _$httpBackend_;
}));

afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});

it('should translate to English', function () {
element = $compile('<p translate>discover_more</p>')($rootScope);
$rootScope.$digest();

$httpBackend.expect('GET', 'langs/en.json').respond(200); // Should I return some data at this point?
$http.get('langs/en.json').then(function () {}); // Should I do something here?
$httpBackend.flush();

expect(element.html()).toBe('Discover more');
});

});


My test of course fails. The thing is that I don't know how to 1) really get the JSON with the data and 2) say the directive "here is your data, do your work".



asked 21 secs ago







Testing with $httpBackend and angular-translate directive

Aucun commentaire:

Enregistrer un commentaire