This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
forked from javve/list.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.parse.js
48 lines (43 loc) · 1.92 KB
/
test.parse.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
describe('Parse', function() {
var list;
before(function() {
$('body').append($('<div id="parse-list">\
<div class="list">\
<div><span class="name">Jonny</span><span class="born">1986</span></div>\
<div><span class="name">Jocke</span><span class="born">1985</span></div>\
</div>\
</div>'));
list = new List('parse-list', {
valueNames: ['name', 'born']
});
});
after(function() {
$('#parse-list').remove();
});
describe('Parse', function() {
it('should have two items', function() {
expect(list.items.length).to.equal(2);
expect(list.items[0].values().name).to.equal("Jonny");
expect(list.items[1].values().name).to.equal("Jocke");
});
it('should add item to parsed list', function() {
list.add({ name: "Sven", born: 1950 });
expect(list.items.length).to.equal(3);
expect(list.items[0].values().name).to.equal("Jonny");
expect(list.items[1].values().name).to.equal("Jocke");
expect(list.items[2].values().name).to.equal("Sven");
expect(list.items[0].values().born).to.equal("1986");
expect(list.items[2].values().born).to.equal(1950);
var el = $($('#parse-list').find('.list div')[2]);
expect(el.find('span').size()).to.equal(2);
expect(el.find('span.name').text()).to.equal('Sven');
expect(el.find('span.born').text()).to.equal('1950');
});
it('should parsed value always be string while added could be number', function() {
expect(list.items[0].values().born).to.equal("1986");
expect(list.items[0].values().born).not.to.equal(1986);
expect(list.items[2].values().born).not.to.equal("1950");
expect(list.items[2].values().born).to.equal(1950);
});
});
});