我正在尝试使用Angular MockE2E测试我的真实API,但是使用.passThrough函数会出错。
这是我的代码:
describe('simple test', function () {
var $controller, $httpBackend;
beforeEach(module('UCA-app'));
beforeEach(inject(function ($rootScope, _$controller_, _$httpBackend_, _SignupService_, _UserService_) {
$controller = _$controller_;
$httpBackend = _$httpBackend_;
SignupService = _SignupService_;
UserService = _UserService_;
$scope = $rootScope.$new();
$httpBackend.whenGET('http://localhost:2684/api/Account/GetPasswordPolicyMessage').passThrough();
}));
});
返回此错误:
错误:意外请求:获取http://localhost:2684/api/Account/GetPasswordPolicyMessage
我试图测试的方法默认情况下在控制器上运行,但是当我改变passthough时会这样:
$httpBackend.expectGET('http://localhost:2684/api/Account/GetPasswordPolicyMessage').passThrough();
我收到错误:
TypeError:$ httpBackend.expectGET(...)。passThrough不是函数
任何想法我做错了,或者我应该设置不同的测试实际的API?