migrated knockout asset to bower
[openemr.git] / public / assets / knockout-2-2-1 / spec / defaultBindings / textBehaviors.js
blobf348ce970e40b74f3f30658d08f1a08bd20f73c1
1 describe('Binding: Text', {
2     before_each: JSSpec.prepareTestNode,
4     'Should assign the value to the node, HTML-encoding the value': function () {
5         var model = { textProp: "'Val <with> \"special\" <i>characters</i>'" };
6         testNode.innerHTML = "<span data-bind='text:textProp'></span>";
7         ko.applyBindings(model, testNode);
8         value_of(testNode.childNodes[0].textContent || testNode.childNodes[0].innerText).should_be(model.textProp);
9     },
11     'Should assign an empty string as value if the model value is null': function () {
12         testNode.innerHTML = "<span data-bind='text:(null)' ></span>";
13         ko.applyBindings(null, testNode);
14         var actualText = "textContent" in testNode.childNodes[0] ? testNode.childNodes[0].textContent : testNode.childNodes[0].innerText;
15         value_of(actualText).should_be("");
16     },
18     'Should assign an empty string as value if the model value is undefined': function () {
19         testNode.innerHTML = "<span data-bind='text:undefined' ></span>";
20         ko.applyBindings(null, testNode);
21         var actualText = "textContent" in testNode.childNodes[0] ? testNode.childNodes[0].textContent : testNode.childNodes[0].innerText;
22         value_of(actualText).should_be("");
23     },
25     'Should work with virtual elements, adding a text node between the comments': function () {
26         var observable = ko.observable("Some text");
27         testNode.innerHTML = "xxx <!-- ko text: textProp --><!-- /ko -->";
28         ko.applyBindings({textProp: observable}, testNode);
29         value_of(testNode).should_contain_text("xxx Some text");
30         value_of(testNode).should_contain_html("xxx <!-- ko text: textprop -->some text<!-- /ko -->");
32         // update observable; should update text
33         observable("New text");
34         value_of(testNode).should_contain_text("xxx New text");
35         value_of(testNode).should_contain_html("xxx <!-- ko text: textprop -->new text<!-- /ko -->");
37         // clear observable; should remove text
38         observable(undefined);
39         value_of(testNode).should_contain_text("xxx ");
40         value_of(testNode).should_contain_html("xxx <!-- ko text: textprop --><!-- /ko -->");
41     },
43     'Should work with virtual elements, removing any existing stuff between the comments': function () {
44         testNode.innerHTML = "xxx <!--ko text: undefined-->some random thing<span> that won't be here later</span><!--/ko-->";
45         ko.applyBindings(null, testNode);
46         value_of(testNode).should_contain_text("xxx ");
47         value_of(testNode).should_contain_html("xxx <!--ko text: undefined--><!--/ko-->");
48     }
49 });