順調に進んでいる単体テストがたくさんあり、プロジェクトに分度器 E2E テストを追加し始めました。ページ上のインタラクティブ要素のテストは問題なく行っていますが、ブラウザから送信される特定のデータのテストに問題があります。
たとえば、特定のボタンをクリックするPOST
と、特定のエンドポイントが生成されるかどうかを確認したいと考えています。
以下を使用して分度器をセットアップしました。
/*globals global*/
module.exports = function() {
'use strict';
var chai = require('chai')
, promised = require('chai-as-promised');
global.expect = chai.expect;
chai.use(promised);
}();
分度器を使用してやり取りする方法を理解しています。
it('send data to the "log" endpoint when clicked', function() {
var repeater = element.all(by.repeater('finding in data.items'));
repeater.get(0).click().then(function() {
// $http expectation
});
});
ただし、イベント$httpBackend
の結果として送信されるデータをキャプチャできるように分度器を設定する方法がわかりません。.click()
追加のモジュールが必要ですか?
Karma/Mocha では、単純に次のようにします。
beforeEach(module('exampleApp'));
describe('logging service', function() {
var $httpPostSpy, LoggingService;
beforeEach(inject(function(_logging_, $http, $httpBackend) {
$httpPostSpy = sinon.spy($http, 'post');
LoggingService = _logging_;
backend = $httpBackend;
backend.when('POST', '/api/log').respond(200);
}));
it('should send data to $http.post', function() [
LoggingService.sendLog({ message: 'logged!'});
backend.flush();
expect($httpPostSpy.args[0][1]).to.have.property('message');
});
});
しかし、分度器$httpBackend
でモジュールへの参照を取得する方法がわかりません。inject