1bb480f6ea
Define a Whisper.View base class that automatically parses and renders templates and attributes defined by the subclass. This saves us a good number of lines of code as well as some marginal memory overhead, since we are no longer saving per-instance copies of template strings.
34 lines
1 KiB
JavaScript
34 lines
1 KiB
JavaScript
describe('Whisper.View', function() {
|
|
it('renders a template with attributes', function() {
|
|
var viewClass = Whisper.View.extend({
|
|
template: '<div>{{ variable }}</div>',
|
|
attributes: {
|
|
variable: 'value'
|
|
}
|
|
});
|
|
|
|
var view = new viewClass();
|
|
view.render();
|
|
assert.strictEqual(view.$el.html(), '<div>value</div>');
|
|
});
|
|
it('renders a template with no attributes', function() {
|
|
var viewClass = Whisper.View.extend({
|
|
template: '<div>static text</div>'
|
|
});
|
|
|
|
var view = new viewClass();
|
|
view.render();
|
|
assert.strictEqual(view.$el.html(), '<div>static text</div>');
|
|
});
|
|
it('renders a template function with attributes function', function() {
|
|
var viewClass = Whisper.View.extend({
|
|
template: function() { return '<div>{{ variable }}</div>'; },
|
|
attributes: function() {
|
|
return { variable: 'value' };
|
|
}
|
|
});
|
|
var view = new viewClass();
|
|
view.render();
|
|
assert.strictEqual(view.$el.html(), '<div>value</div>');
|
|
});
|
|
});
|