Permalink
Browse files

Extend the specs for setDomNodeChildrenFromArrayMapping to include re…

…placing a value through an observable item.
  • Loading branch information...
1 parent 3146a3a commit 35704d94a6769587b23c6e1115f39b9f22c748a5 @mbest mbest committed Feb 25, 2012
Showing with 15 additions and 3 deletions.
  1. +15 −3 spec/editDetectionBehaviors.js
@@ -62,7 +62,12 @@ describe('Compare Arrays', {
describe('Array to DOM node children mapping', {
before_each: function () {
+ var existingNode = document.getElementById("testNode");
+ if (existingNode != null)
+ existingNode.parentNode.removeChild(existingNode);
testNode = document.createElement("div");
+ testNode.id = "testNode";
+ document.body.appendChild(testNode);
},
'Should populate the DOM node by mapping array elements': function () {
@@ -158,7 +163,7 @@ describe('Array to DOM node children mapping', {
var mapping = function (arrayItem) {
mappingInvocations.push(arrayItem);
var output = document.createElement("DIV");
- output.innerHTML = arrayItem || "null";
+ output.innerHTML = ko.utils.unwrapObservable(arrayItem) || "null";
return [output];
};
var callback = function(arrayItem, nodes) {
@@ -184,9 +189,16 @@ describe('Array to DOM node children mapping', {
value_of(countCallbackInvocations).should_be(mappingInvocations.length);
mappingInvocations = [], countCallbackInvocations = 0;
- ko.utils.setDomNodeChildrenFromArrayMapping(testNode, [1, null, "B"], mapping, null, callback); // Add to beginning; delete from end
+ var observable = ko.observable(1);
+ ko.utils.setDomNodeChildrenFromArrayMapping(testNode, [observable, null, "B"], mapping, null, callback); // Add to beginning; delete from end
value_of(ko.utils.arrayMap(testNode.childNodes, function (x) { return x.innerHTML })).should_be(["1", "null", "B"]);
- value_of(mappingInvocations).should_be([1, null]);
+ value_of(mappingInvocations).should_be([observable, null]);
+ value_of(countCallbackInvocations).should_be(mappingInvocations.length);
+
+ mappingInvocations = [], countCallbackInvocations = 0;
+ observable(2); // Change the value of the observable
+ value_of(ko.utils.arrayMap(testNode.childNodes, function (x) { return x.innerHTML })).should_be(["2", "null", "B"]);
+ value_of(mappingInvocations).should_be([observable]);
value_of(countCallbackInvocations).should_be(mappingInvocations.length);
}
});

0 comments on commit 35704d9

Please sign in to comment.