Skip to content

Commit 42d7c5c

Browse files
committed
Fix remaining review findings
1 parent 6683b8b commit 42d7c5c

File tree

6 files changed

+34
-24
lines changed

6 files changed

+34
-24
lines changed

builds/knockout/spec/defaultBindings/valueBehaviors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ describe('Binding: Value', function() {
151151
expect(mySetter.set).to.deep.equal('668');
152152

153153
// ['property']
154-
testNode.childNodes[0].value = 669;
155-
ko.utils.triggerEvent(testNode.childNodes[0], "change");
154+
testNode.childNodes[2].value = 669;
155+
ko.utils.triggerEvent(testNode.childNodes[2], "change");
156156
expect(mySetter.set).to.deep.equal('669');
157157
});
158158

builds/knockout/spec/dependentObservableBehaviors.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('Dependent Observable', function() {
7070
var someContainer = { depObs: instance };
7171
someContainer.depObs("some value");
7272
expect(invokedWriteWithValue).to.deep.equal("some value");
73-
expect(invokedWriteWithThis).to.deep.equal(function(){return this;}.call()); // Since no owner was specified
73+
expect(invokedWriteWithThis).to.equal(function(){return this;}.call()); // Since no owner was specified
7474
});
7575

7676
it('Should be able to write to multiple computed properties on a model object using chaining syntax', function() {
@@ -112,7 +112,7 @@ describe('Dependent Observable', function() {
112112
expect(invokedWriteWithArgs[0]).to.deep.equal("first");
113113
expect(invokedWriteWithArgs[1]).to.deep.equal(2);
114114
expect(invokedWriteWithArgs[2]).to.deep.equal(["third1", "third2"]);
115-
expect(invokedWriteWithThis).to.deep.equal(someOwner);
115+
expect(invokedWriteWithThis).to.equal(someOwner);
116116
});
117117

118118
it('Should use the second arg (evaluatorFunctionTarget) for "this" when calling read/write if no options.owner was given', function() {
@@ -124,8 +124,8 @@ describe('Dependent Observable', function() {
124124

125125
instance("force invocation of write");
126126

127-
expect(actualReadThis).to.deep.equal(expectedThis);
128-
expect(actualWriteThis).to.deep.equal(expectedThis);
127+
expect(actualReadThis).to.equal(expectedThis);
128+
expect(actualWriteThis).to.equal(expectedThis);
129129
});
130130

131131
it('Should be able to pass evaluator function using "options" parameter called "read"', function() {

builds/knockout/spec/templatingBehaviors.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,20 @@ export var dummyTemplateEngine = function (templates) {
5555

5656
templateText = options.showParams ? templateText + ", data=" + data + ", options=" + options : templateText;
5757
var templateOptions = options.templateOptions; // Have templateOptions in scope to support [js:templateOptions.foo] syntax
58-
59-
data = data || {};
60-
var nomangle$data = data;
58+
var renderData = data == null ? {} : data;
59+
var nomangle$data = renderData;
6160
window.__prevent_tree_shaking__ = nomangle$data;
6261
delete window.__prevent_tree_shaking__;
6362

64-
options.templateRenderingVariablesInScope = options.templateRenderingVariablesInScope || {};
65-
ko.utils.extend(data, options.templateRenderingVariablesInScope);
63+
var templateRenderingVariablesInScope = options.templateRenderingVariablesInScope || {};
64+
var scopeData = {};
65+
if (renderData && (typeof renderData === 'object' || typeof renderData === 'function')) {
66+
ko.utils.extend(scopeData, renderData);
67+
}
68+
ko.utils.extend(scopeData, templateRenderingVariablesInScope);
6669

6770
var result = templateText.replace(/\[renderTemplate\:(.*?)\]/g, function (match, templateName) {
68-
return ko.renderTemplate(templateName, data, options);
71+
return ko.renderTemplate(templateName, renderData, options);
6972
});
7073

7174
result = result.replace(/\[\[js\:([\s\S]*?)\]\]/g, evalHandler);
@@ -78,10 +81,10 @@ export var dummyTemplateEngine = function (templates) {
7881
bindingContext: bindingContext,
7982
ko: ko,
8083
nomangle$data: nomangle$data,
81-
root: data,
84+
root: renderData,
8285
templateOptions: templateOptions,
8386
unwrap: ko.utils.unwrapObservable
84-
}, bindingContext, data, options.templateRenderingVariablesInScope);
87+
}, bindingContext, scopeData);
8588
with (scope) {
8689
evalResult = eval(script);
8790
}

packages/bind/spec/asyncBindingBehaviors.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,16 @@ describe('Deferred bindings', function () {
6161
}
6262
})
6363
afterEach(function () {
64-
expect(tasks.resetForTesting()).to.equal(0)
65-
while (cleanups.length) {
66-
cleanups.pop()!()
64+
const pendingTasks = tasks.resetForTesting()
65+
try {
66+
while (cleanups.length) {
67+
cleanups.pop()!()
68+
}
69+
} finally {
70+
clock.restore()
71+
bindingSpy = bindingHandlers.test = null
6772
}
68-
clock.restore()
69-
bindingSpy = bindingHandlers.test = null
73+
expect(pendingTasks).to.equal(0)
7074
})
7175

7276
it('Should update bindings asynchronously', function () {

packages/bind/spec/bindingAttributeBehaviors.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ import { bindings as coreBindings } from '@tko/binding.core'
2525
import { bindings as templateBindings } from '@tko/binding.template'
2626
import { bindings as ifBindings } from '@tko/binding.if'
2727

28-
import { expectContainHtml, expectContainText, prepareTestNode, restoreAfter } from '../../utils/helpers/mocha-test-helpers'
28+
import {
29+
expectContainHtml,
30+
expectContainText,
31+
prepareTestNode,
32+
restoreAfter
33+
} from '../../utils/helpers/mocha-test-helpers'
2934
import { Provider } from '@tko/provider'
3035

3136
describe('Binding attribute syntax', function () {
@@ -392,9 +397,7 @@ describe('Binding attribute syntax', function () {
392397
testNode.innerHTML = "<div data-bind='test1: true, test2: true'></div>"
393398
expect(function () {
394399
applyBindings(null, testNode)
395-
}).to.throw(
396-
'Multiple bindings (test1 and test2) are trying to control descendant bindings of the same element.'
397-
)
400+
}).to.throw('Multiple bindings (test1 and test2) are trying to control descendant bindings of the same element.')
398401
})
399402

400403
it('Should use properties on the view model in preference to properties on the binding context', function () {

packages/bind/spec/bindingHandlerBehaviors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('BindingHandler behaviors', function () {
102102
this.subscribe(obs, this.cb)
103103
}
104104
cb() {
105-
expect(this).to.equal(handlerInstance)
105+
expect(this).to.equal(handlerInstance)
106106
}
107107
}
108108
testNode.innerHTML = "<i data-bind='fnHandler'></i>"

0 commit comments

Comments
 (0)