有没有人有一个想法如何嘲笑角e2e测试$ httpBackend? 这个想法是在travis-ci上运行测试时对XHR请求进行存根操作。 我正在使用karma代理Travis上运行的rails应用程序中的资产和部分。 我想做没有真正的数据库查询验收测试。
这里是我的人缘配置文件的一部分:
...
files = [
MOCHA,
MOCHA_ADAPTER,
'spec/javascripts/support/angular-scenario.js',
ANGULAR_SCENARIO_ADAPTER,
'spec/javascripts/support/angular-mocks.js',
'spec/javascripts/e2e/**/*_spec.*'
];
...
proxies = {
'/app': 'http://localhost:3000/',
'/assets': 'http://localhost:3000/assets/'
};
...
这里是我的规格文件的一部分:
beforeEach(inject(function($injector){
browser().navigateTo('/app');
}));
it('should do smth', inject(function($rootScope, $injector){
input('<model name>').enter('smth');
//this is the point where I want to stub real http query
pause();
}));
我试图获得$ httpBackend到$注射器服务:
$injector.get('$httpBackend')
但是这不是在我的测试运行的iframe内部使用的。
下一个尝试,我用angular.scenario.dsl做,这里是代码samle:
angular.scenario.dsl('mockHttpGet', function(){
return function(path, fakeResponse){
return this.addFutureAction("Mocking response", function($window, $document, done) {
// I have access to window and document instances
// from iframe where my tests run here
var $httpBackend = $document.injector().get(['$httpBackend']);
$httpBackend.expectGET(path).respond(fakeResponse)
done(null);
});
};
});
用例:
it('should do smth', inject(function($rootScope, $injector){
mockHttpGet('<path>', { /* fake data */ });
input('search.name').enter('mow');
pause();
}));
这将导致以下错误:
<$httpBackend listing> has no method 'expectGET'
所以,在这一点上,我不知道下一步。有没有人尝试过这样的事情,这种类型的茬真的有可能吗?
你如何配置你的业力在你的规范中有“注入”功能?我一直在为我的测试收到ReferenceError – wakandan