代码之家  ›  专栏  ›  技术社区  ›  Neshta

我只能同时运行7个QUnit测试

  •  0
  • Neshta  · 技术社区  · 10 年前

    我在运行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 回复  |  直到 10 年前
        1
  •  0
  •   Neshta    10 年前

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