我想测试我的控制器,我使用过'控制器作为'在应用程序中,现在我正在测试自己。
控制器:(控制器的一半)
(0,0)
测试:
(0,0)
我收到错误消息:
TypeError:' undefined'不是一个对象(评估' MainCtrl.ctrl') 在/Applications/MAMP/htdocs/test/spec/controllers/main.js:22
我知道它必须是一个小工具才能让它工作......任何人都可以提供帮助吗?
谢谢堆
答案 0 :(得分:1)
这应该涵盖它......
var MainCtrl, scope;
beforeEach(function() {
module('donateApp');
inject(function($controller, $rootScope) {
scope = $rootScope.$new();
MainCtrl = $controller('MainCtrl as ctrl', {
$scope: scope
});
});
});
it('publishes the controller on the scope as ctrl', function() {
// you don't need this test, it's just to show you that
// scope.ctrl is set correctly when using the "controller as" syntax
expect(scope.ctrl).toBe(MainCtrl);
});
it('Expect the form start with submitted as false', function() {
expect(MainCtrl.submitted).toBeFalsy();
});