嗨,伙计, 目前我正在测试我的JavaScript代码与Qunit测试框架。我无法在QUnit.test函数中访问我的QUnit.module设置变量。访问Qunit模块安装变量
QUnit.module("Module A:Build Notes",{
setup: function() {
this.inputsticky = $("input[name=stickyinput]");
}
});
QUnit.test("Test Case 1",function (assert) {
assert.expect(1);
orangeClick(); //changing color
assert.equal(this.inputsticky.css('background-color'),'rgb(255, 165, 0)', "orange Function passed !");
});
结果: this.inputsticky未定义
这是行不通的,QUnit不工作的方式。但更重要的是,你为什么要在测试中选择元素? – jakerella
@jakerella我需要为许多测试用例使用该输入元素。所以为了减少一些冗余,我将元素存储在变量(this.inputsticky)中,并在必要时调用相同的元素。 –
是的......但我认为QUnit不会像'this'那样工作。您可以简单地在模块外面定义一个变量。我会为此添加一个答案 – jakerella