2
我想創建一個與BDD(行爲驅動開發)的jQuery模塊。應該jquery組件返回false
這裏是我的組件
(function($) {
function MyModule(element){
return false;
}
$.fn.myModule = function() {
var args = Array.prototype.slice.call(arguments, 1);
return this.each(function() {
new MyModule(this);
});
};
$.fn.myModule.Constructor = MyModule;
})(window.jQuery);
這裏是我的測試
QUnit.test("test", function(assert) {
assert.expect(1);
var smallBox = $('<div/>',{'id':'smallBox'}).width(200).height(200);
var result = smallBox.myModule();
console.log(result); // This gives the HTML element itself but I am expecting it must be boolean false
assert.notOk(result, "should return false");
});
我有2個問題。
1-如果我的組件返回布爾值,該怎麼辦?它是錯誤的模式?
2-如何我可以從我的組件
所以驗證應該在$ .fn.myModule內 –
@MehmetErenYener是的,你應該積累所有'新的MyModule'調用的結果,然後返回該值。 –