使用Qunit测试Knockout Extender

时间:2013-10-14 18:26:55

标签: knockout.js qunit chutzpah

我正在尝试为下面的Knockout扩展器编写一个qUnit测试。我似乎正在走错路,任何有关如何纠正我的单元测试的提示都将受到赞赏。

ko.extenders.AddItems = function (array, items)
{
    var mutated = false;
    var underlyingArray = array();
    for (var $i2 = 0, $l2 = items.length, item = items[$i2]; $i2 < $l2; $i2++, item = items[$i2])
    {
        underlyingArray.push(item);
        mutated = true;
    }
    if (mutated)
    {
        ko.extenders.ArrayHasMutated(array);
    }
};

单元测试:

test("RemoveItemsTest", function () {

    var startArray = new Array();
    startArray[0] = "1";
    startArray[1] = "2";
    startArray[2] = "3";

    var remArray = new Array();
    remArray[0] = "2";

    var compareArray = new Array();
    compareArray[0] = "1";
    compareArray[2] = "3";


    ko.extenders.RemoveItems(startArray, remArray);

    equal(startArray, compareArray);


});

0 个答案:

没有答案