-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathview.js
60 lines (49 loc) · 1.96 KB
/
view.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
describe('HandlebarsView', function() {
describe('rendering', function() {
it('should return itself', function() {
var view = new HandlebarsView();
view.render().should.equal(view);
});
it('should render a template function', function() {
var MyView = HandlebarsView.extend({
template: function(context) {
context.should.deep.equal({name: 'World', foo: 'bar'});
return 'Hello ' + context.name + '!';
}
});
var view = new MyView({model: {name: 'World', foo: 'bar'}});
view.render().$el.html().should.equal('Hello World!');
});
it('should render a string template', function() {
var originalCompile = Handlebars.compile;
Handlebars.compile = function(template) {
return function(context) {
context.should.deep.equal({name: 'World', foo: 'bar'});
return template.replace('{{name}}', context.name);
};
};
var MyView = HandlebarsView.extend({
template: 'Hello {{name}}!'
});
var view = new MyView({model: {name: 'World', foo: 'bar'}});
view.render().$el.html().should.equal('Hello World!');
Handlebars.compile = originalCompile;
});
});
describe('context', function() {
it('should use this.model as context if defined', function() {
var view = new HandlebarsView({model: {name: 'World'}});
view.context().should.deep.equal({name: 'World'});
});
it('should use this.collection if defined and this.model undefined', function() {
var view = new HandlebarsView({collection: ['World']});
view.context().should.deep.equal(['World']);
view = new HandlebarsView({model: {name: 'World'}, collection: ['World']});
view.context().should.deep.equal({name: 'World'});
});
it('should default to {} when this.collection and this.model are undefined', function() {
var view = new HandlebarsView();
view.context().should.deep.equal({});
});
});
});