I wrote a test that mocks a request to server which should return an array. The problem is, that when i launch my test it gives me error:
Cannot read property 'get' of null
and when i debug it is clear, that $http is null for some reason, but if i launch my code, it sends a request to server. Maybe my mystake is that i am using $http directly from controller, maybe i should use service for that and it would solve the problem? Anyway, my main question is why $http is null and what am i doing wrong?
Code in controller:
$scope.getLastReview = () => { $http.get('/lastReview').success((reviewArray: any) => { $scope.reviewsToShow = reviewArray; }); };
My test:
var sut = createController();
scope.getLastReview();
httpBackend.expectGET("/lastReview").respond(200, reviewArray);
httpBackend.flush();
expect(reviewArray.length).toBeGreaterThan(0);
Aucun commentaire:
Enregistrer un commentaire