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
Post a Comment