-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
124 lines (109 loc) · 2.59 KB
/
test.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { expect } from 'chai';
import ArrayPortal from './';
describe('ArrayPortal', () => {
it('returns a object', () => {
expect(ArrayPortal({output:'',input:'',caller:''})).to.be.a('object');
});
it('throws an error if no object is passed', () => {
expect(() => {
ArrayPortal();
}).to.throw(Error);
});
it('throw an error if no input/output/caller is given', () => {
expect(() => {
ArrayPortal({
not: '',
that: '',
what: '',
we: '',
expect: ''
});
}).to.throw(Error);
});
it('returns an object with input/output arrays', () => {
expect(ArrayPortal({output:'',input:'',caller:''})).to.deep.equal({output:[],input:[]})
});
it('returns a object with teleported by caller with type string', () => {
let teleported = ArrayPortal({
caller: 'a',
input: ['a','b','c'],
output: ['d','e']
});
expect(teleported).to.deep.equal({
input: ['b','c'],
output: ['d','e','a']
});
});
it('returns also a empty array if caller was the last item in array', () => {
let teleported = ArrayPortal({
caller: 'a',
input: ['a'],
output: []
});
expect(teleported).to.deep.equal({
input: [],
output: ['a']
});
});
it('uses the lodash-findIndex method if you pass a object as caller', () => {
let teleported = ArrayPortal({
caller: {
id: 'a'
},
input: [{
id: 'a'
}],
output: []
});
expect(teleported).to.deep.equal({
input: [],
output: [{
id: 'a'
}]
});
})
it('uses the lodash-findIndex method if you pass a object as caller', () => {
let teleported = ArrayPortal({
caller: {
id: 123
},
input: [{
id: 3,
title: 'foobar'
},{
id: 39,
title: 'nom nom nom'
},{
id: 123,
title: 'Portal it baby!'
}],
output: [{
id: 1337,
title: 'my door is open dude'
}]
});
expect(teleported).to.deep.equal({
input: [{
id: 3,
title: 'foobar'
},{
id: 39,
title: 'nom nom nom'
}],
output: [{
id: 1337,
title: 'my door is open dude',
},{
id: 123,
title: 'Portal it baby!'
}]
});
});
it('doesnt edit the original used arrays', () => {
let inputArr = ['a','b','c'];
let outputArr = ['d','e'];
let caller = 'a';
ArrayPortal({ caller: caller, input: inputArr, output: outputArr });
expect(inputArr).to.deep.equal(['a','b','c']);
});
});