我有一堆被顺利单元测试,我已经开始量角器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()
事件而发送的数据。我需要额外的模块吗?
在噶/摩卡我只想:
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
模块。