Currently I am using John Papa style data services as in example below and the problem with this approach is that I am getting "SyntaxError: Parse error" at 3rd line when trying to write a unit test for "getAvengers()" method:
Service:
function getAvengers() {
return $http.get('/api/maa')
.then(getAvengersComplete);
function getAvengersComplete(response) {
return response.data.results;
}
}
Unit test:
describe("getAvengers", function() {
var mockData = {
data: {
results: ["test 1", "test2"]
}
};
it("", function(done) {
$httpBackend.when('GET', "/api/maa").respond(200, mockData);
dataservice.getAvengers()
.then(function(data) {
expect(data).toEqual(mockData.data.results);
done();
})
$rootScope.$apply();
$httpBackend.flush();
});
});
Question
Why I am getting parse error at this point? Unit test starts to work when I make these changes:
function getAvengers() {
return $http.get('/api/maa')
.then(function(response) {
return response.data.results;
});
//function getAvengersComplete(response) {
// return response.data.results;
//}
}
Aucun commentaire:
Enregistrer un commentaire