以下对 location.path 的间谍失败并出现错误:
试图将未定义的属性路径包装为函数
it('should redirect location.path', function() { sinon.spy(location, 'path'); scope.create(); expect(location.path).to.have.been.calledOnce; location.path.restore();
模拟控制器:
describe('AdminUsersController', function() {
var Users;
beforeEach(inject(function(_$controller_, $rootScope, $location, _Users_, _$httpBackend_) {
var location;
scope = $rootScope.$new();
location = $location;
controller = _$controller_('AdminUsersController', {
$scope: scope,
$location: location
});
我正在尝试测试的行:
$scope.create = function() {
return $location.path("admin/users/newuser?create");
};