$scope.login = function(){
api.getToken($scope.username, $scope.password, function(){
$scope.loggedIn = true;
});
};
it('should work', function(){
scope.login();
expect(scope.loggedIn).toBe(true); // fails
});
我该如何测试这个功能?对scope.loggedIn
的测试失败,因为它仍然是false
。噶如何测试这个角码?
是,所有的测试代码?您需要模拟'api.getToken'并解决它以将登录设置为true。 – codemonkey
我该怎么做? – userqwert
如果您在角度测试中查找文档,您会发现对“spyOn”的引用。这就是你需要使用的。 – codemonkey