I’m using jasmine + grunt-karma for writing unit test. I’ve a controller which has $ionicViewService as dependency.
The issue encountered when unit testing the controller:
TypeError: Cannot read property 'historyId' of null
at Object.clearHistory (/../app/bower_components/ionic/release/js/ionic-angular.js:3376:23)
at new <anonymous> (/../app/bower_components/angular/angular.js:3906:17)
What could have caused this error ?
My Controller:
angular.module('cApp').controller('MyCtrl', function($scope, $ionicViewService) {
$ionicViewService.clearHistory();
...
}
My Unit test:
describe('MyCtrl', function() {
var scope, controller;
// Load the module
beforeEach(function () {
module('cApp');
module('ionic');
});
beforeEach(inject(function($rootScope, $controller) {
scope = $rootScope.$new();
controller = $controller('MyCtrl', {
$scope: scope
});
}));
it('should have the controller', inject(function() {
expect(controller).toBeDefined();
}));
});