We are working on angularjs and displaying map on page using leaflet.
Along with this we are using jasmine(1.3.1.5) for the tests.
I have a test controller as:
angular.module('TestProject').controller('TestCtrl', ['$scope', 'leafletData', function TestCtrl($scope, leafletData){
'use strict';
$scope.map;
leafletData.getMap().then(function(map) {
var southWest = L.latLng(-90, -180),
northEast = L.latLng(90, 180),
bounds = L.latLngBounds(southWest, northEast);
mapObj.setMaxBounds(bounds);
mapObj.options.maxZoom = 19;
mapObj.options.minZoom = 1;
$scope.map=map;
$scope.featureGroup = L.featureGroup().addTo($scope.map);
});
}]);
And the spec for it is:
"use strict";
describe("test controller",function() {
var scope,leafletData, compile;
beforeEach(module("TestProject"));
beforeEach(inject(function($controller, $rootScope, $compile, leafletData) {
scope = $rootScope.$new();
compile = $compile;
$controller('TestCtrl', {
'$scope' : scope,
'leafletData' : leafletData
});
}));
it("test function", function() {
var element = angular.element('<leaflet></leaflet>');
element = compile(element)(scope);
expect(leafletData).toBeDefined();
leafletData.getMap().then(function(map) {
scope.map = map;
});
$rootScope.$digest();
//expect(scope.map.getZoom()).toEqual(1);
//expect(scope.map.getCenter().lat).toEqual(0);
//expect(scope.map.getCenter().lng).toEqual(0);
});
});
The error we get on running the spec:
1.) test controller it test function <<< FAILURE!
* Expected undefined to be defined.
* TypeError: 'undefined' is not an object (evaluating
'leafletData.getMap') in
http://localhost:49594/spec/controllers/org/testCtrlSpec.js (line 22)
We have specifically imported all js files available within leaflet-directive. But still leafletData is undefined. We had the feeling that this could be due to the difference in module name. Therefore I tried "beforeEach(module("TestProject", "leaflet-directive"));" but still it doesn't work. Seems we are missing out on some configuration. Please help!!