Skip to content

Commit

Permalink
Add tests for "prepareStateForRender"
Browse files Browse the repository at this point in the history
  • Loading branch information
yuchi committed Dec 16, 2016
1 parent 25416ba commit 70c4cd8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/metal-soy/test/Soy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Events as EventsComponent } from './assets/Events.soy.js';
// on it.
// TODO: We should have a better dependency management for soy files so that
// the order in which they're required doesn't matter.
import { ComputedData as ComputedDataComponent } from './assets/ComputedData.soy.js';
import { ExternalTemplate as ExternalTemplateComponent } from './assets/ExternalTemplate.soy.js';
import { Functions as FunctionsComponent } from './assets/Functions.soy.js';
import { HtmlContent as HtmlContentComponent } from './assets/HtmlContent.soy.js';
Expand Down Expand Up @@ -111,6 +112,27 @@ describe('Soy', function() {
done();
});
});

it('should pass state values to "getTemplateData" and use them in the template', function(done) {
ComputedDataComponent.prototype.shouldUpdate = function() {
return true;
};

ComputedDataComponent.prototype.prepareStateForRender = function(data) {
data.name = data.name.split('').reverse().join('');
};

comp = new ComputedDataComponent({ name: 'Foo' });

assert.strictEqual('ooF', comp.element.textContent);

comp.name = 'Bar';

comp.once('stateSynced', function() {
assert.strictEqual('raB', comp.element.textContent);
done();
});
});
});

it('should not add sub template soy params as state keys', function() {
Expand Down
10 changes: 10 additions & 0 deletions packages/metal-soy/test/assets/ComputedData.soy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{namespace ComputedData}

/**
* @param name
*/
{template .render}
<div>
{$name}
</div>
{/template}

0 comments on commit 70c4cd8

Please sign in to comment.