【问题标题】:Sinon catch xmlhttprequest诗乃捕捉 xmlhttprequest
【发布时间】:2015-07-15 01:50:33
【问题描述】:

我有一个关于诗乃测试的问题。我正在使用mochacasper,我想捕获单击按钮后发送的 XMLHttpRequest。到目前为止,我无法收到请求...

casper.then(function () {
  this.fill(...);
});
casper.then(function() {
  this.click('#myButton');
});
casper.then(function () {
  //I want to catch the request/response here
});

由于我使用的是我的测试环境数据库,我知道我的请求已发送,因为我的测试数据已添加到我的数据库中。 我试过sinon's useFakeXMLHttpRequestsinon's fakeServer,但都没有工作。

那么我怎样才能捕捉到请求呢?

【问题讨论】:

标签: javascript jquery mocha.js casperjs sinon


【解决方案1】:

我用Artjom B. 的评论开发了一个“可行的”结果。 这不是我所需要的,但目前已经足够了......

我是这样做的:

casper.then(function () {
this.click('button[data-hook="submitButton"]');
});
casper.waitForResource(function (resource) {
 return resource.status === 201;
}, function () {
this.echo('Appointment has been created');
});

唯一的问题仍然是,我无法访问响应的正文,但至少我可以检查状态是否正确。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-04
    • 2019-07-07
    • 2017-05-12
    • 1970-01-01
    • 2013-08-25
    • 1970-01-01
    相关资源
    最近更新 更多