Skip to content

Commit

Permalink
Test changes to fix issues in older browsers (IE and Firefox)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbest committed Dec 29, 2017
1 parent 9059a9a commit a804d02
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion spec/asyncBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("Throttled observables", function() {
// Wait until after timeout
waitsFor(function() {
return notifiedValues.length > 0;
}, 300);
}, 500);
runs(function() {
expect(notifiedValues.length).toEqual(1);
expect(notifiedValues[0]).toEqual("F");
Expand Down
8 changes: 4 additions & 4 deletions spec/asyncBindingBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe("Deferred bindings", function() {

it('Should update "if" binding before descendant bindings', function() {
// Based on example at https://github.com/knockout/knockout/pull/2226
testNode.innerHTML = '<div data-bind="if: hasAddress()"><span data-bind="text: streetNumber().toLowerCase()"></span> <span data-bind="text: street().toLowerCase()"></span></div>';
testNode.innerHTML = '<div data-bind="if: hasAddress()"><span data-bind="text: streetNumber().toLowerCase()"></span><span data-bind="text: street().toLowerCase()"></span></div>';
var vm = {
street: ko.observable(),
streetNumber: ko.observable(),
Expand All @@ -167,7 +167,7 @@ describe("Deferred bindings", function() {
vm.street('my street');
vm.streetNumber('123');
jasmine.Clock.tick(1);
expect(testNode.childNodes[0]).toContainText('123 my street');
expect(testNode.childNodes[0]).toContainText('123my street');

vm.street(null);
vm.streetNumber(null);
Expand All @@ -177,7 +177,7 @@ describe("Deferred bindings", function() {

it('Should update "with" binding before descendant bindings', function() {
// Based on example at https://github.com/knockout/knockout/pull/2226
testNode.innerHTML = '<div data-bind="with: hasAddress()"><span data-bind="text: $parent.streetNumber().toLowerCase()"></span> <span data-bind="text: $parent.street().toLowerCase()"></span></div>';
testNode.innerHTML = '<div data-bind="with: hasAddress()"><span data-bind="text: $parent.streetNumber().toLowerCase()"></span><span data-bind="text: $parent.street().toLowerCase()"></span></div>';
var vm = {
street: ko.observable(),
streetNumber: ko.observable(),
Expand All @@ -191,7 +191,7 @@ describe("Deferred bindings", function() {
vm.street('my street');
vm.streetNumber('123');
jasmine.Clock.tick(1);
expect(testNode.childNodes[0]).toContainText('123 my street');
expect(testNode.childNodes[0]).toContainText('123my street');

vm.street(null);
vm.streetNumber(null);
Expand Down
16 changes: 8 additions & 8 deletions spec/bindingAttributeBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,42 +325,42 @@ describe('Binding attribute syntax', function() {
});

it('Should reject closing virtual bindings without matching open, when found as a sibling', function() {
testNode.innerHTML = "<div></div><!-- /ko -->";
testNode.innerHTML = "x<div></div><!-- /ko -->x";
expect(function() {
ko.applyBindings(null, testNode);
}).toThrow();
});

it('Should reject closing virtual bindings without matching open, when found as a a first child', function() {
testNode.innerHTML = "<div><!-- /ko --></div>";
testNode.innerHTML = "<div>x<!-- /ko -->x</div>";
expect(function() {
ko.applyBindings(null, testNode);
}).toThrow();
});

it('Should reject closing virtual bindings, when found as first child at the top level', function() {
testNode.innerHTML = "<!-- /ko -->";
testNode.innerHTML = "x<!-- /ko -->x";
expect(function() {
ko.applyBindings(null, testNode);
}).toThrow();
});

it('Should reject duplicated closing virtual bindings', function() {
testNode.innerHTML = "<!-- ko if: true --><div></div><!-- /ko --><!-- /ko -->";
testNode.innerHTML = "x<!-- ko if: true --><div></div><!-- /ko --><!-- /ko -->x";
expect(function() {
ko.applyBindings(null, testNode);
}).toThrow();
});

it('Should reject opening virtual bindings that are not closed', function() {
testNode.innerHTML = "<!-- ko if: true -->";
testNode.innerHTML = "x<!-- ko if: true -->x";
expect(function() {
ko.applyBindings(null, testNode);
}).toThrow();
});

it('Should reject virtual bindings that are nested incorrectly', function() {
testNode.innerHTML = "<!-- ko if: true --><div><!-- /ko --></div>";
testNode.innerHTML = "x<!-- ko if: true --><div><!-- /ko --></div>x";
expect(function() {
ko.applyBindings(null, testNode);
}).toThrow();
Expand Down Expand Up @@ -604,13 +604,13 @@ describe('Binding attribute syntax', function() {
var callbacks = 0,
callback = function (nodes, data) {
expect(nodes.length).toEqual(1);
expect(nodes[0]).toEqual(testNode.childNodes[1]);
expect(nodes[0]).toEqual(testNode.childNodes[2]);
expect(data).toEqual(vm);
callbacks++;
},
vm = { callback: callback };

testNode.innerHTML = "<!-- ko childrenComplete: callback --><span data-bind='text: \"Some Text\"'></span><!-- /ko -->";
testNode.innerHTML = "begin <!-- ko childrenComplete: callback --><span data-bind='text: \"Some Text\"'></span><!-- /ko --> end";
ko.applyBindings(vm, testNode);
expect(callbacks).toEqual(1);
});
Expand Down
12 changes: 9 additions & 3 deletions spec/defaultBindings/attrBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ describe('Binding: Attr', function() {
].join('');

ko.applyBindings(model, testNode);
var anchor = testNode.childNodes[0]/*svg*/.childNodes[0]/*g*/.childNodes[0]/*a*/;
expect( anchor.getAttributeNode('xlink:href').value ).toEqual( 'first value' );
expect( anchor.getAttributeNode('xlink:href').namespaceURI ).toEqual( 'http://www.w3.org/1999/xlink' );

var anchor = testNode.childNodes[0]/*svg*/.childNodes[0]/*g*/.childNodes[0]/*a*/;
if (anchor && "getAttributeNode" in anchor) {
var anchorAttribute = anchor.getAttributeNode('xlink:href');
expect(anchorAttribute.value).toEqual('first value');
if (anchorAttribute.namespaceURI) {
expect(anchorAttribute.namespaceURI).toEqual('http://www.w3.org/1999/xlink');
}
}
});

it('Should be able to set \"name\" attribute, even on IE6-7', function() {
Expand Down
2 changes: 1 addition & 1 deletion spec/defaultBindings/styleBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Binding: CSS style', function() {
// Represents https://github.com/knockout/knockout/issues/972
testNode.innerHTML = "<div data-bind='style: { width: 0 }'></div>";
ko.applyBindings(null, testNode);
expect(testNode.childNodes[0].style.width).toBe("0px");
expect(testNode.childNodes[0].style.width).toEqualOneOf(["0px", "0pt"]);
});

it('Should be able to apply the numeric value to a style that doesn\'t accept pixels', function() {
Expand Down
14 changes: 7 additions & 7 deletions spec/defaultBindings/withBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,26 +220,26 @@ describe('Binding: With', function() {
ko.applyBindings({ item: item }, testNode);
expect(item.getSubscriptionsCount('change')).toEqual(3); // subscriptions are the with and value bindings, and the binding context
expect(testNode.childNodes[0]).toHaveValues(['one']);
expect(testNode.childNodes[0]).toContainText('one');
expect(testNode.childNodes[0].childNodes[1]).toContainText('one');

// Should update observable when input is changed
testNode.childNodes[0].childNodes[0].value = 'two';
ko.utils.triggerEvent(testNode.childNodes[0].childNodes[0], "change");
expect(item()).toEqual('two');
expect(testNode.childNodes[0]).toContainText('two');
expect(testNode.childNodes[0].childNodes[1]).toContainText('two');

// Should update the input when the observable changes
item('three');
expect(testNode.childNodes[0]).toHaveValues(['three']);
expect(testNode.childNodes[0]).toContainText('three');
expect(testNode.childNodes[0].childNodes[1]).toContainText('three');

// subscription count is stable
expect(item.getSubscriptionsCount('change')).toEqual(3);
});

it('Should update if given a function', function () {
// See knockout/knockout#2285
testNode.innerHTML = '<div data-bind="with: getTotal">Total: <div data-bind="text: $data"></div>';
testNode.innerHTML = '<div data-bind="with: getTotal"><div data-bind="text: $data"></div>';

function ViewModel() {
var self = this;
Expand All @@ -253,13 +253,13 @@ describe('Binding: With', function() {

var model = new ViewModel();
ko.applyBindings(model, testNode);
expect(testNode).toContainText("Total: 4");
expect(testNode).toContainText("4");

model.items.push({ x: ko.observable(15) });
expect(testNode).toContainText("Total: 19");
expect(testNode).toContainText("19");

model.items()[0].x(10);
expect(testNode).toContainText("Total: 25");
expect(testNode).toContainText("25");
});

it('Should call a childrenComplete callback function', function () {
Expand Down
6 changes: 3 additions & 3 deletions spec/utilsDomBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('cloneNodes', function () {

it ('should return clones', function() {
var newNodes = ko.utils.cloneNodes([testNode]);
var isClone = !testNode.isSameNode(newNodes[0]) && testNode.isEqualNode(newNodes[0]);
var isClone = testNode.isSameNode ? !testNode.isSameNode(newNodes[0]) && testNode.isEqualNode(newNodes[0]) : testNode !== newNodes[0];
expect(isClone).toBe(true);
});

Expand All @@ -108,9 +108,9 @@ describe('cloneNodes', function () {
testNode.appendChild(child);

var newNodes = ko.utils.cloneNodes([testNode]);
var newChild = newNodes[0].children[0];
var newChild = newNodes[0].childNodes[0];

var childIsClone = !child.isSameNode(newChild) && child.isEqualNode(newChild);
var childIsClone = child.isSameNode ? !child.isSameNode(newChild) && child.isEqualNode(newChild) : child !== newChild;

expect(childIsClone).toBe(true);
});
Expand Down

0 comments on commit a804d02

Please sign in to comment.