Skip to content

Commit

Permalink
Failing test for UI.dynamic #6
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Oct 9, 2014
1 parent 370b973 commit 9796158
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
9 changes: 9 additions & 0 deletions dynamic_template_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
{{/with}}
</template>

<template name="DynamicParentDataOnTemplateDynamic">
{{! rename to Template.dynamic in 0.9.4}}
{{> UI.dynamic template='_DynamicParentDataOnTemplateDynamic' data=getData}}
</template>

<template name="_DynamicParentDataOnTemplateDynamic">
{{> DynamicTemplate template="WithData"}}
</template>

<template name="InheritedParentData">
{{#with 'outer'}}
{{#with 'inner'}}
Expand Down
49 changes: 49 additions & 0 deletions dynamic_template_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ Template.DynamicParentData.helpers({
}
});


Template.DynamicParentDataOnTemplateDynamic.helpers({
getData: function () {
var res = reactiveData.get();
return res;
}
});

Template.DynamicWithBlock.helpers({
getTemplate: function () {
// like session.get
Expand Down Expand Up @@ -196,6 +204,47 @@ Tinytest.add('DynamicTemplate - Rendering with dynamic parent data', function (t
});
});


Tinytest.add('DynamicTemplate - Rendering with dynamic parent data from Template.dynamic', function (test) {
var renderCount = 0;
Template.WithData.rendered = function () {
renderCount++;
};

// star the data value off as an empty string so the template still renders
reactiveData._value = 'init';

withRenderedTemplate('DynamicParentDataOnTemplateDynamic', function (el) {
// we've rendered the template to the page
test.equal(renderCount, 1);

// but no data yet
test.equal(el.innerHTML.compact(), 'WithData-init');

// now set the data
reactiveData.set('1');
Deps.flush();

// should not re-render
test.equal(renderCount, 1);

// but data should be updated
test.equal(el.innerHTML.compact(), 'WithData-1');

// now set the data again
reactiveData.set('2');
Deps.flush();

// should not re-render
test.equal(renderCount, 1);

// but data should be updated
test.equal(el.innerHTML.compact(), 'WithData-2');

reactiveData.clear();
});
});

/*
Tinytest.add('DynamicTemplate - Rendering inherits data correctly', function (test) {
withRenderedTemplate('InheritedParentData', function (el) {
Expand Down

0 comments on commit 9796158

Please sign in to comment.