-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
35 lines (25 loc) · 770 Bytes
/
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
'use strict';
const expect = require('chai').expect;
const findById = require('.');
describe('findById()', () => {
const tree = [
{ id: 1 },
{ id: 2, children: [{ id: 3 }]},
]
it('creates a search function', () => {
const fn = findById('children');
expect(fn(tree, 'id', 1)).to.eql({ id: 1 });
});
it('works on nested elements', () => {
const fn = findById('children');
expect(fn(tree, 'id', 3)).to.eql({ id: 3 });
});
it('creates a search function with a pre-defined key', () => {
const fn = findById('children', 'id');
expect(fn(tree, 1)).to.eql({ id: 1 });
});
it('returns undefined if nothing is found', () => {
const fn = findById('children');
expect(fn(tree, 'id', 4)).to.be.undefined;
});
});