Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add failing spec to demonstrate bug 739

  • Loading branch information...
commit b819e1047385ff6ddfedc57475ec92b0bb567d46 1 parent 6eefcf6
@SteveSanderson SteveSanderson authored
Showing with 18 additions and 0 deletions.
  1. +18 −0 spec/templatingBehaviors.js
View
18 spec/templatingBehaviors.js
@@ -445,6 +445,24 @@ describe('Templating', function() {
expect(testNode.childNodes[0]).toContainHtml("<div>new</div>inner <span>123</span>x");
});
+ it('Data binding \'foreach\' should handle templates in which the very first node has a binding but it does not reference any observables', function() {
+ // Represents https://github.com/SteveSanderson/knockout/issues/739
+ // Previously, the rewriting (which introduces a comment node before the bound node) was interfering
+ // with the array-to-DOM-node mapping state tracking
+ ko.setTemplateEngine(new dummyTemplateEngine({ mytemplate: "<div data-bind='attr: {}'>[js:name()]</div>" }));
+ testNode.innerHTML = "<div data-bind=\"template: { name: 'mytemplate', foreach: items }\"></div>";
+
+ // Bind against array, referencing an observable property
+ var myItem = { name: ko.observable("a") };
+ ko.applyBindings({ items: [myItem] });
+ expect(testNode.childNodes[0]).toContainHtml("<div>a</div>");
+
+ // Modify the observable property and check that UI is updated
+ // Previously with the bug, it wasn't updated because the removal of the memo comment caused the array-to-DOM-node computed to be disposed
+ myItem.name("b");
+ expect(testNode.childNodes[0]).toContainHtml("<div>b</div>");
+ });
+
it('Data binding \'foreach\' option should apply bindings with an $index in the context', function () {
var myArray = new ko.observableArray([{ personName: "Bob" }, { personName: "Frank"}]);
ko.setTemplateEngine(new dummyTemplateEngine({ itemTemplate: "The item # is <span data-bind='text: $index'></span>" }));
Please sign in to comment.
Something went wrong with that request. Please try again.