forked from javve/list.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.add-get-remove.js
97 lines (89 loc) · 3.11 KB
/
test.add-get-remove.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
describe('Add, get, remove', function() {
var list;
before(function() {
list = fixture.list(['name'], [ { name: "Jonny" } ]);
});
after(function() {
fixture.removeList();
});
afterEach(function() {
list.clear();
list.add({ name: "Jonny" });
});
describe('Add', function() {
it('should add one item', function() {
list.add({ name: 'Jonas' });
expect(list.items.length).to.equal(2);
});
it('should add two items', function() {
list.add([
{ name: 'Martina' },
{ name: 'Angelica' }
]);
expect(list.items.length).to.equal(3);
});
it('should add async items', function(done) {
list.add([
{ name: 'Sven' }
], function() {
expect(list.items.length).to.equal(2);
done();
});
});
it('should add async items to empty list', function(done) {
list.clear();
list.add([
{ name: 'Sven' }
], function() {
expect(list.items.length).to.equal(1);
done();
});
});
});
describe('Get', function() {
it('should return array with one item', function() {
var items = list.get('name', 'Jonny');
expect(items[0].values().name).to.equal('Jonny');
});
it('should return empty array', function() {
var items = list.get('name', 'jonny');
expect(items.length).to.be.zero;
});
it('should return two items', function() {
list.add({ name: 'Jonny' });
var items = list.get('name', 'Jonny');
expect(items.length).to.equal(2);
expect(items[0].values().name).to.equal('Jonny');
expect(items[1].values().name).to.equal('Jonny');
});
});
describe('Remove', function() {
it('should remove one item', function() {
list.add({ name: "Jonas" });
expect(list.items.length).to.equal(2);
var count = list.remove('name', 'Jonas');
expect(count).to.equal(1);
expect(list.items.length).to.equal(1);
});
it('should not remove anything due to case sensitivity', function() {
var count = list.remove('name', 'jonny');
expect(count).to.be.equal(0);
expect(list.items.length).to.equal(1);
});
it('should remove eight items', function() {
list.add({ name: 'Jonny' });
list.add({ name: 'Jonny' });
list.add({ name: 'Sven' });
list.add({ name: 'Jonny' });
list.add({ name: 'Jonny' });
list.add({ name: 'Jonny' });
list.add({ name: 'Jonas' });
list.add({ name: 'Jonny' });
list.add({ name: 'Jonny' });
expect(list.items.length).to.equal(10);
var count = list.remove('name', 'Jonny');
expect(count).to.equal(8);
expect(list.items.length).to.equal(2);
});
});
});