我尝试使用 QUnit 异步测试来检查 ajax 更新。
我在这里阅读了 QUnit.asyncTest
https://www.sitepoint.com/test-asynchronous-code-qunit/
但如果我尝试这个,我会得到一个
TypeError: QUnit.asyncTest is not a function
完整的来源:https ://gist.github.com/232457b002e5363439aece7535600356
当然,我是使用 QUnit 的新手,并且使用 JavaScript 的时间不长。
发生错误的部分的片段:
function max() {
var max = -Infinity;
for (var i = 0; i < arguments.length; i++) {
if (arguments[i] > max) {
max = arguments[i];
}
}
return max;
}
// https://www.sitepoint.com/test-asynchronous-code-qunit/
//TypeError: QUnit.asyncTest is not a function
QUnit.asyncTest('max', function (assert) {
expect(1);
window.setTimeout(function() {
assert.strictEqual(max(3, 1, 2), 3, 'All positive numbers');
QUnit.start();
}, 0);
});
该测试没有给出语法错误,但给出了旧日期:
QUnit.test('usersInnerHTMLlength_Is24', function(assert) {
// problem: this not reads the updates done by ajax. means that are old data:
let innerHTMLlength = $("#users").html().toString().length;
assert.equal(innerHTMLlength, 24);
});
可能无法使用 QUnit 检查 ajax 吗?当我读到这里时,我想这个: QUnit testing AJAX calls
我在 Wordpress 插件中使用它