有沒有人有一個想法如何嘲笑角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