Skip to content

Commit

Permalink
Merge pull request knockout#899 from SteveSanderson/fix-818-specs
Browse files Browse the repository at this point in the history
Fix specs that were failing in IE6-8 when innerText was blank
  • Loading branch information
rniemeyer committed Mar 26, 2013
2 parents 30a68e4 + 72ea11d commit e530b98
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 2 additions & 4 deletions spec/defaultBindings/optionsBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ describe('Binding: Options', function() {
]);
testNode.innerHTML = "<select data-bind='options:myValues, optionsText: function (v) { return v[\"name\"] + \" (\" + v[\"job\"] + \")\"; }'><option>should be deleted</option></select>";
ko.applyBindings({ myValues: modelValues }, testNode);
var displayedText = ko.utils.arrayMap(testNode.childNodes[0].childNodes, function (node) { return node.innerText || node.textContent; });
expect(displayedText).toEqual(["bob (manager)", "frank (coder & tester)"]);
expect(testNode.childNodes[0]).toHaveTexts(["bob (manager)", "frank (coder & tester)"]);
});

it('Should accept a function in optionsValue param to select subproperties of the model values (and use that for the option text)', function() {
Expand All @@ -48,8 +47,7 @@ describe('Binding: Options', function() {
testNode.innerHTML = "<select data-bind='options: myValues, optionsValue: function (v) { return v.name + \" (\" + v.job + \")\"; }'><option>should be deleted</option></select>";
ko.applyBindings({ myValues: modelValues }, testNode);
expect(testNode.childNodes[0]).toHaveValues(["bob (manager)", "frank (coder & tester)"]);
var displayedText = ko.utils.arrayMap(testNode.childNodes[0].childNodes, function (node) { return node.innerText || node.textContent; });
expect(displayedText).toEqual(["bob (manager)", "frank (coder & tester)"]);
expect(testNode.childNodes[0]).toHaveTexts(["bob (manager)", "frank (coder & tester)"]);
});

it('Should exclude any items marked as destroyed', function() {
Expand Down
8 changes: 6 additions & 2 deletions spec/lib/jasmine.extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ jasmine.Matchers.prototype.toContainHtml = function (expectedHtml) {
return cleanedHtml === expectedHtml;
};

jasmine.nodeText = function(node) {
return 'textContent' in node ? node.textContent : node.innerText;
}

jasmine.Matchers.prototype.toContainText = function (expectedText) {
var actualText = 'textContent' in this.actual ? this.actual.textContent : this.actual.innerText;
var actualText = jasmine.nodeText(this.actual);
var cleanedActualText = actualText.replace(/\r\n/g, "\n");
this.actual = cleanedActualText; // Fix explanatory message
return cleanedActualText === expectedText;
Expand All @@ -36,7 +40,7 @@ jasmine.Matchers.prototype.toHaveOwnProperties = function (expectedProperties) {
};

jasmine.Matchers.prototype.toHaveTexts = function (expectedTexts) {
var texts = ko.utils.arrayMap(this.actual.childNodes, function (node) { return node.innerText || node.textContent; });
var texts = ko.utils.arrayMap(this.actual.childNodes, jasmine.nodeText);
this.actual = texts; // Fix explanatory message
return this.env.equals_(texts, expectedTexts);
};
Expand Down

0 comments on commit e530b98

Please sign in to comment.