dimanche 1 février 2015

Unit test for a funtion in AngularJS controller which calls to a function in Onsen UI with Jasmine

I am making a unit test for a function of a controller in AngularJS code, this function will call to a function in Onsen UI code. But I fail when run it.


My code and my test code as bellow:


- In app.js file:



var module = angular.module('app', ['onsen']);
module.controller('myctrl', ['$scope', function($scope) {
$scope.startpop = function(index) {
$scope.index = index;
ons.navigator.popPage();
};
}]);


- in test.spec.js file:



describe("test myctrl:", function() {
var $controller;

beforeEach(function() {
angular.module('onsen');
module('app');
});

beforeEach(inject(function(_$controller_) {
$controller = _$controller_;
}));

it('test startpop() function', function() {
var $scope = {};
var controller = $controller('myctrl', {$scope: $scope});
$scope.startpop(3);

expect($scope.index).toEqual(3);
});


But I met error when run unit test as bellow:


TypeError: Cannot read property 'popPage' of undefined


Please help me to solve it ?


Aucun commentaire:

Enregistrer un commentaire