angularjs - method does not exist when calling spyOn -


i'm trying use jasmine spyon call angularjs controller function. keep getting following error:

submit() method not exist.

what missing in order work?

    describe('myctrler', function() {     beforeeach(module('mymodule'));     var scope,ctrl;     beforeeach(inject(function($rootscope, $controller) {       scope = $rootscope.$new();         spyon(scope, "submit");       ctrl = $controller('myctrler', {           $scope: scope       });     }));     it('controller defined', inject(function() {         expect(ctrl).tobedefined();     }));     it('controller function', function() {         expect(submit).tobedefined();     });     });    angular.module('mymodule').controller('myctrler',function($scope){        var vm = this;        vm.submit = function() {        };      }); 

as per question missed bind method scope. need make below. hope helps.

it('controller function', function() {             expect(ctrl.submit).tobedefined();         }); 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -