Skip to content

Commit

Permalink
Fixed two specs that were giving false negatives on IE<9.
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveSanderson committed Dec 13, 2011
1 parent fca15fd commit df9acea
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
26 changes: 24 additions & 2 deletions spec/defaultBindingsBehaviors.js
Expand Up @@ -1471,8 +1471,30 @@ describe('Binding: Foreach', {

'Should be able to nest containerless templates directly inside UL elements, even on IE < 8 with its bizarre HTML parsing/formatting' : function() {
// Represents https://github.com/SteveSanderson/knockout/issues/212
// Note that the </li> tags are omitted, to simulate IE<9's weird parsing, hence the <!-- /ko --> tags are moved into the <li>
ko.utils.setHtml(testNode, "<ul><!-- ko foreach: ['A', 'B'] --><!-- ko if: $data == 'B' --><li data-bind='text: $data'><!-- /ko --><!-- /ko --></ul>");
// This test starts with the following DOM structure:
// <ul>
// <!-- ko foreach: ['A', 'B'] -->
// <!-- ko if: $data == 'B' -->
// <li data-bind='text: $data'>
// <!-- /ko -->
// <!-- /ko -->
// </li>
// </ul>
// Note that:
// 1. The closing comments are inside the <li> to simulate IE<8's weird parsing
// 2. We have to build this with manual DOM operations, otherwise IE<8 will deform it in a different weird way
// It would be a more authentic test if we could set up the scenario using .innerHTML and then let the browser do whatever parsing it does normally,
// but unfortunately IE varies its weirdness according to whether it's really parsing an HTML doc, or whether you're using .innerHTML.

testNode.innerHTML = "";
testNode.appendChild(document.createElement("ul"));
testNode.firstChild.appendChild(document.createComment("ko foreach: ['A', 'B']"));
testNode.firstChild.appendChild(document.createComment("ko if: $data == 'B'"));
testNode.firstChild.appendChild(document.createElement("li"));
testNode.firstChild.lastChild.setAttribute("data-bind", "text: $data");
testNode.firstChild.lastChild.appendChild(document.createComment("/ko"));
testNode.firstChild.lastChild.appendChild(document.createComment("/ko"));

ko.applyBindings(null, testNode);
value_of(testNode).should_contain_text("B");
},
Expand Down
9 changes: 6 additions & 3 deletions spec/runner.html
Expand Up @@ -4,9 +4,12 @@
<title>JSSpec results</title>
<link rel="stylesheet" type="text/css" href="lib/JSSpec.css" />

<!-- All specs should pass with or without jQuery being referenced -->
<!-- <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script> -->

<!-- All specs should pass with or without jQuery+Modernizr being referenced -->
<!--
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/modernizr/modernizr-1.7-development-only.js"></script>
-->

<script type="text/javascript" src="lib/innershiv.js"></script>
<script type="text/javascript" src="lib/diff_match_patch.js"></script>
<script type="text/javascript" src="lib/JSSpec.js"></script>
Expand Down

0 comments on commit df9acea

Please sign in to comment.