在我的量角器测试中,我还想验证是否进行了正确的ajax调用。例如,如果我导航到/chapters,我希望确保存在对/chapters/documents?page=1的ajax调用
用量角器能做到这一点吗?
我发现this帖子有一些有趣的解决方案,但我仍然不知道如何使用它,以便在我的it(...)中可以实际测试一些东西。例如。browser.addMockModule听起来很有前途,但同样,我应该在我的beforeEach中做什么,以及我如何验证任何东西。如果能帮上忙,我们将不胜感激!
发布于 2017-02-10 01:19:55
您可以尝试下面这样的方法。在您的测试中添加一个模拟模块:
browser.addMockModule('httpInterceptor', function () {
angular.module('httpInterceptor', []).factory('httpRequestInterceptor',function ($q) {
return {
request: function (request) {
window.handledRequests = window.handledRequests || [];
window.handledRequests.push({
url: request.url,
method: request.method,
params: request.params,
data: JSON.stringify(request.data)
});
return request || $q.when(request);
}
};
}).config(function ($httpProvider) {
$httpProvider.interceptors.push('httpInterceptor');
});
});然后,您可以在测试中编写断言,如下所示:
browser.controlFlow().execute(function () {
browser.executeScript(function () {
return window.handledRequests;
}).then(function (handledRequests) {
// assert content of handledRequests
});
});https://stackoverflow.com/questions/36410402
复制相似问题