I've only done a small bit of testing in AngularJS using Jasmine and Karma (test runner) but I am stuck at the moment. I am integrating google maps on a partial view and I am eager to test the functions I wrote for It in the corresponding controller (placing a marker when a click happens, changing the radius of a circle on the map,...)
All the functionality works but testing it seems a lot harder. This is a simple test that I am using to verify that a service is defined:
it('should contain a locationDbService',
function () {
expect(locationDbService).toBeDefined();
});
I have the following code executed before each test:
var ctrl, scope, locationDbService;
// inject the $controller and $rootScope services
// in the beforeEach block
beforeEach(inject(function ($controller, $rootScope, _LocationDbService_) {
// Create a new scope that's a child of the $rootScope
scope = $rootScope.$new();
// Create the controller
ctrl = $controller('AddLocationCtrl', {
$scope: scope,
LocationDbService: _LocationDbService_
});
locationDbService = _LocationDbService_;
}));
The controller header is the following:
.controller('AddLocationCtrl', function ($scope, LocationDbService) {
Initialize function in the controller:
var map;
$scope.initialize = function () {
var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(51.142036, 4.440966)
};
map = new google.maps.Map(document.getElementById('map-canvas-add-location'), mapOptions);
};
google.maps.event.addDomListener(window, "load", $scope.initialize());
View:
<div class="item item-body">
<div id="map-canvas-add-location"></div>
</div>
The problem I encountered at the start was:
I "fixed" it by added the google maps js file to the Karma conf files array, is this a correct solution?
When I add the js file and run the test again I get the following failure:
I've been searching the web for a solution for many hours now and can't find any of them to be working. What am I doing wrong?
Thanks in advance!