rivets-bfeach-binder.spec.js
3.2 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
define(function(require) {
'use strict';
var $ = require('jquery');
window.jQuery = $;
var RivetsBFEachUtil = require('rivets-bfeach-binder');
require('rivets-backbone-adapter-brainfood');
var _ = require('underscore');
var Backbone = require('backbone');
var rivets = require('rivets');
//rivets.config.rootInterface = ':';
/* global console:false */
describe('RivetsBFEachUtil', function() {
it('returns defined', function() {
expect(RivetsBFEachUtil).toBeDefined();
});
var rootScope, rootNode, rivetsView;
function makeTest(rootData, rootHtml, rootTests) {
beforeEach(function() {
rootScope = new Backbone.Model(rootData);
rootNode = $($.parseHTML(rootHtml));
rivetsView = rivets.bind(rootNode, rootScope);
});
rootTests();
}
makeTest({
sub: new Backbone.Model({
list: new Backbone.Collection([
{key: 'A'},
{key: 'B'},
{key: 'C'},
], {parse: true}),
}),
list: new Backbone.Collection([
{key: 'A'},
{key: 'B'},
{key: 'C'},
], {parse: true}),
constant: 'this-is-a-constant',
}, '<div>{:constant}<div rv-bfeach-item=":list">key:{:item:key} constant:{:constant}</div><div rv-bfeach-item=":sub:list">sub-key:{:item:key} constant:{:constant}</div</div>', function() {
it('foo', function() {
expect(rootNode.html()).toEqual(
'this-is-a-constant'
+ '<!-- rivets: bfeach-item -->'
+ '<div>key:A constant:this-is-a-constant</div>'
+ '<div>key:B constant:this-is-a-constant</div>'
+ '<div>key:C constant:this-is-a-constant</div>'
+ '<!-- rivets: bfeach-item -->'
+ '<div>sub-key:A constant:this-is-a-constant</div>'
+ '<div>sub-key:B constant:this-is-a-constant</div>'
+ '<div>sub-key:C constant:this-is-a-constant</div>'
);
});
describe('foo', function() {
beforeEach(function() {
//rootScope.set('constant', 'updated-constant');
rootScope.get('list').add({key: 'D'}, {at: -1, parse: true});
});
it('bar', function() {
expect(rootNode.html()).toEqual(
'updated-constant'
+ '<!-- rivets: bfeach-item -->'
+ '<div>key:A constant:updated-constant</div>'
+ '<div>key:B constant:updated-constant</div>'
+ '<div>key:C constant:updated-constant</div>'
+ '<!-- rivets: bfeach-item -->'
+ '<div>sub-key:A constant:updated-constant</div>'
+ '<div>sub-key:B constant:updated-constant</div>'
+ '<div>sub-key:C constant:updated-constant</div>'
);
});
});
});
});
});