I have solved this problem by wrapping each of the ajax requests in the asyncTest() method.
I can run only 7 QUnit tests at the same time
-
17-06-2023 - |
Question
I have got a problem with running QUnit tests. I have some async tests on my page.
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
All tests were run clear and passed separately. But if they were running at the same time, only the first 7 tests were run.
I think I miss out something... Can you help me?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow