【发布时间】:2015-09-01 04:49:15
【问题描述】:
我最近发现了一个很棒的 ng-describe 包,它通过抽象出所有你必须记住/查找和编写以便加载、注入、模拟或间谍。
有人尝试将ng-describe 与protractor 一起使用吗?这有意义吗?我们能从中受益吗?
引起我注意的一件事是您可以轻松地模拟 HTTP 响应:
ngDescribe({
inject: '$http', // for making test calls
http: {
get: {
'/my/url': 42, // status 200, data 42
'/my/other/url': [202, 42], // status 202, data 42,
'/my/smart/url': function (method, url, data, headers) {
return [500, 'something is wrong'];
} // status 500, data "something is wrong"
},
post: {
// same format as GET
}
},
tests: function (deps) {
it('responds', function (done) {
deps.$http.get('/my/other/url')
.then(function (response) {
// response.status = 202
// response.data = 42
done();
});
http.flush();
});
}
});
模拟 HTTP 响应通常有助于实现更好的 e2e 覆盖并测试 UI 如何对特定情况做出反应以及错误处理如何工作。这是我们目前正在使用protractor-http-mock 做的事情,还有other options 看起来不像ng-describe 那样容易。
【问题讨论】:
标签: javascript angularjs testing protractor ngdescribe