2014-03-19 21 views
0

我在运行QUnit测试时遇到了问题。我在我的页面上有一些异步测试。我只能同时运行7个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次测试运行。

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

回答

0

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