嗨,夥計, 目前我正在測試我的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