您好我是Javascript Qunit的新手。你能否告诉我为什么全局变量没有得到更新值的功能。
这是我的代码:
var x =0;
QUnit.test('myTest', function (assert) {
require(["purchase"], function (purchase) {
x = 10;
});
assert.equal(window.x, 10, "1 is equal to 1 : PASS");
//window.x value still showing 0;
});
请帮帮我。
答案 0 :(得分:0)
require
调用是异步的,因此在测试运行时尚未完成,请在内部添加asset
require(["purchase"], function (purchase) {
x = 10;
/* move the test inside the callback */
assert.equal(window.x, 10, "1 is equal to 1 : PASS");
});