Repository navigation
Expand file tree
/
Copy pathUtil.js
More file actions
31 lines (29 loc) · 1.39 KB
/
Copy pathUtil.js
File metadata and controls
31 lines (29 loc) · 1.39 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
import {expect} from 'chai';
import {firstDefined, closestAbove} from '../src/Util';
describe('Util', () => {
describe('firstDefined', () => {
it("should return the first argument that is defined", function () {
expect(firstDefined(1,2)).to.equal(1);
expect(firstDefined(0,1,2)).to.equal(0);
expect(firstDefined(undefined,1,2)).to.equal(1);
expect(firstDefined(undefined,undefined,2)).to.equal(2);
expect(firstDefined(undefined,undefined,undefined)).to.equal(undefined);
expect(firstDefined(undefined,undefined,null)).to.equal(null);
expect(firstDefined('1','2')).to.equal('1');
expect(firstDefined('0','1','2')).to.equal('0');
expect(firstDefined(undefined,'1','2')).to.equal('1');
expect(firstDefined(undefined,undefined,'2')).to.equal('2');
expect(firstDefined(undefined,'undefined',undefined)).to.equal('undefined');
expect(firstDefined(undefined,undefined,'null')).to.equal('null');
});
});
describe('closestAbove()', () => {
it('should return the first item in list that is greater or equal to the given value', () => {
expect(closestAbove([1,10,100], 5)).to.equal(10);
expect(closestAbove([1,10,100], undefined)).to.equal(100);
expect(closestAbove([1,10,100], 500)).to.equal(100);
expect(closestAbove([100,10,1], 5)).to.equal(100);
expect(closestAbove([], 5)).to.equal(undefined);
})
});
});