所以我的空白测试通过了这个设置。
describe('loginController', function() {
var scope, createController;
beforeEach(module('souply'));
beforeEach(inject(function ($rootScope, $controller, _$location_) {
$location = _$location_;
scope = $rootScope.$new();
createController = function() {
return $controller('loginController', {
'$scope': scope
});
};
}));
以下是测试......
describe('processGoogleLogin', function(){
describe('successful', function(){
beforeEach(function() {
});
it('should connect to google plus', function () {
expect(true).toBe(true);
});
这个没有问题。
问题:如何在登录控制器上测试方法?
以下是我想在登录控制器上测试的方法:
$scope.processGoogleLogin = function(){
console.log('process login was clicked');
window.location.replace('/#/dashboard');
};
我到目前为止的测试是:
it('should sign you into the dashboard', function () {
scope.processGoogleLogin();
//$controller.processGoogleLogin();
//expect(window.location).toBe('/#/dashboard');
});
此测试抛出错误:
'undefined' is not a function (evaluating 'scope.processGoogleLogin()')
答案 0 :(得分:0)
这需要这一行。
var ctrl = $controllerConstructor('myController', {$scope: scope, myResolve: {}, state: state});