【问题标题】:Cannot run multiple karma tests using suave server无法使用 suave 服务器运行多个业力测试
【发布时间】:2016-07-19 21:58:26
【问题描述】:

当我单独运行以下测试(通过注释掉)时,每个测试都会通过。但是,当我运行所有测试时,我得到一个 XmlHttpRequest 未捕获的异常。 suave 测试服务器接收请求并且日志显示没有错误或问题:

var HOME_URL = "http://localhost:3000/request";

it("should echo the test request with response", function (done) {
    var test = { act: 'test1', qry: {} };

    var promise = webix.ajax().post(HOME_URL, JSON.stringify(test));

    console.log('test1');
    promise.then(function (resp) {
        expect(resp.json().succ).to.be(true);
        done();
    }).fail(function (err) {
        done();
        throw(err);
    });

});


it("should echo the test request with response 2", function (done) {
    var test = { act: 'test2', qry: {} };

    var promise = webix.ajax().post(HOME_URL, JSON.stringify(test));

    console.log('test2');
    promise.then(function (resp) {
        expect(resp.json().succ).to.be(true);
        done();
    }).fail(function (err) {
        console.log('echo test error', app.util.inspect(promise));
        done();
        throw(err);
    });

});

任何想法可能是什么问题或如何调试这些测试?

要自己运行代码(必须安装 git node 和 npm):

git clone http://github.com/halcwb/GenUnitApp.git cd GenUnitApp git checkout failingServer scripts/run.sh

打开第二个终端

./build.sh clienttests

当否决票请解释,然后我可以改进我的问题。

【问题讨论】:

    标签: karma-runner webix suave


    【解决方案1】:

    对于遇到这种情况的任何人,您可以将 ajax 调用嵌套在 before 函数中,然后在您的测试中使用 promises(webix.ajax 返回一个 promise),例如:

    var HOME_URL = "http://localhost:3000/request";
    var test1, test2;
    
    before(function () {
        var req = { act: 'test1', qry: {}};
    
        test1 = webix.ajax().post(HOME_URL, JSON.stringify(req));
        req.act = "test2";
        test2 = webix.ajax().post(HOME_URL, JSON.stringify(req));
    });
    
    it("should echo the test request with response", function (done) {
        var promise = test1;
    
        promise.then(function (resp) {
            expect(resp.json().succ).to.be(true);
            done();
        }).fail(function (err) {
            done();
            throw(err);
        });
    
    });
    
    
    it("should echo the test request with response 2", function (done) {
        var promise = test2;
    
        promise.then(function (resp) {
            expect(resp.json().succ).to.be(true);
            done();
        }).fail(function (err) {
            done();
            throw(err);
        });
    
    });
    

    投反对票时请解释一下,我努力学习。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-01
      • 2019-12-10
      • 2019-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多