我在其上运行我的 e2e 测试的 Angular 应用程序没有 ngApp 指令和手动引导。在这种情况下是否可以通过 Protractor 插入模拟模块?
//load angular mocks as a string here
var angularMocks = require('./angularMocks.module.js').mock;
browser.addMockModule("ngMockE2E", angularMocks );
browser.addMockModule('httpBackendMock', function httpBackendMock() {
console.log('inside httpBackendMock');
angular.module("httpBackendMock", ['ngMockE2E'])
.run(['$httpBackend', function ($httpBackend) {
console.log("Inside Run");
$httpBackend.whenGET(/.*employees.*/).respond(404, '');
$httpBackend.whenGET(/.*/).passThrough();
$httpBackend.whenPOST(/.*/).passThrough();
$httpBackend.whenPUT(/.*/).passThrough();
}]);
});
browser.get(url);
这会在浏览器控制台中记录“inside httpBackendMock”,而不是“Inside Run”,这表明 API 调用从未被拦截。