我可以同时运行7个QUnit测试

时间:2014-03-19 13:09:24

标签: javascript unit-testing qunit

我遇到运行QUnit测试的问题。我的页面上有一些异步测试。

var sendInvalidData = function (httpMethod, data) {
    $.ajax({
        url: '@AppSettings.ApiUrl' + 'api/parties',
        type: httpMethod,
        headers: { 'Authorization': 'Bearer ' + accessToken },
        dataType: "json",
        data: data,
        timeout: 5000
    }).done(function (response) {
        ok(!response.Success, _.first(response.Errors));
    }).fail(function (x, text, thrown) {
        ok(false, "Ajax failed: " + text);
    }).always(function () {
        start();
    });
};

asyncTest("GET api/parties/Available", function () {
    $.ajax({
        url: '@AppSettings.ApiUrl' + 'api/parties/Available',
        type: "GET",
        headers: { 'Authorization': 'Bearer ' + accessToken },
        timeout: 5000
    }).done(function (data) {
        ok(data.Success, "Is response success");
    }).fail(function (x, text, thrown) {
        ok(false, "Ajax failed: " + text);
    }).always(function () {
        start();
    });
});

asyncTest("POST api/parties", function () {
    // The Name field is required.
    sendInvalidData("POST" ,{
        IsPrivate: false,
        Color: 1
    });

    sendInvalidData("POST", {
        Name: "new party",
        Color: 1
    });

    sendInvalidData("POST", {
        Name: "new party",
        IsPrivate: true,
        Color: 1
    });

    sendInvalidData("POST", {
        Name: "new party",
        IsPrivate: false
    });

    sendInvalidData("POST", {
        Name: "new party",
        IsPrivate: false,
        Password: "123",
        Color: 1
    });

    $.ajax({
        url: '@AppSettings.ApiUrl' + 'api/parties',
        type: "POST",
        headers: { 'Authorization': 'Bearer ' + accessToken },
        dataType: "json",
        data: {
            Name: "new party",
            IsPrivate: false,
            Color: 1
        },
        timeout: 5000
    }).done(function (response) {
        ok(response.Success, "Party has created successfully.");
    }).fail(function (x, text, thrown) {
        ok(false, "Ajax failed: " + text);
    }).always(function () {
        start();
    });
});

asyncTest("POST api/parties", function () {
    // another N tests
});

// more async tests

所有测试都清晰运行并单独通过。但如果它们同时运行,则只运行前7个测试。

我想我错过了一些东西......你能帮助我吗?

1 个答案:

答案 0 :(得分:0)

我通过在asyncTest()方法中包装每个ajax请求来解决这个问题。

相关问题