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 ?

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to