Мне нужна помощь, чтобы протестировать контроллер, который получает объект базы данных.Это моя первая настоящая попытка тестирования, поэтому очень важно указывать в правильном направлении.Мой контроллер:
angular.module('myAPP')
.controller ('DetailsController', function ($scope, $http, $routeParams) {
var id = $routeParams.id;
$http.get("/api/car/" + id)
.success(function (data) {
$scope.car = data;
});
});
Я уже тестировал реальный текст на HTML-странице (который работает, кстати), поэтому я включил это в свой тестовый файл.Это о втором тесте.
describe('page contact ', function () {
//initialize Angular
beforeEach(module('myAPP'));
//parse out the scope for use in our unit tests.
var scope;
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
var ctrl = $controller('ContactController', { $scope: scope });
}));
it('initial text is contact ', function () {
var text3 = scope.message3;
expect(text3).toMatch("contact");
});
});
describe('details page ', function () {
//initialize Angular
beforeEach(module('myAPP'));
//parse out the scope for use in our unit tests.
//need some help here...
var scope;
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
var ctrl = $controller('DetailsController', { $scope: scope });
//need some help here...
}));
it('need some help here....');
});