1

I need some help on how to unit test a controller which get a database object. This is my first actual try on testing, so pointing in the right direction is much appreciated. My controller:

angular.module('myAPP')
.controller ('DetailsController', function ($scope, $http, $routeParams) {
    var id = $routeParams.id;
    $http.get("/api/car/" + id)
        .success(function (data) {
            $scope.car = data;
        });
});

I already tested on actual text on a html page (which works btw), so I include this in my testfile. It;s about the second test.

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....');

});

0 Answers0