Skip to content

Commit

Permalink
Add specs for $context binding property
Browse files Browse the repository at this point in the history
  • Loading branch information
mbest committed Sep 24, 2012
1 parent be8564f commit 5d5839b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/bindingAttributeBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ describe('Binding attribute syntax', {
value_of(testNode).should_contain_text("DIV");
},

'Should be able to use $context in binding value to refer to the context object': function() {
testNode.innerHTML = "<div data-bind='text: $context.$data === $data'></div>";
ko.applyBindings({}, testNode);
value_of(testNode).should_contain_text("true");
},

'Should be able to refer to the bound object itself (at the root scope, the viewmodel) via $data': function() {
testNode.innerHTML = "<div data-bind='text: $data.someProp'></div>";
ko.applyBindings({ someProp: 'My prop value' }, testNode);
Expand Down
6 changes: 6 additions & 0 deletions spec/templatingBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ describe('Templating', {
value_of(testNode.childNodes[0]).should_contain_text("DIV");
},

'Data binding syntax should be able to use $context in binding value to refer to the context object': function() {
ko.setTemplateEngine(new dummyTemplateEngine({ someTemplate: "<div data-bind='text: $context.$data === $data'></div>" }));
ko.renderTemplate("someTemplate", {}, null, testNode);
value_of(testNode.childNodes[0]).should_contain_text("true");
},

'Data binding syntax should defer evaluation of variables until the end of template rendering (so bindings can take independent subscriptions to them)': function () {
ko.setTemplateEngine(new dummyTemplateEngine({
someTemplate: "<input data-bind='value:message' />[js: message = 'goodbye'; undefined; ]"
Expand Down

0 comments on commit 5d5839b

Please sign in to comment.