-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
48 lines (43 loc) · 965 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
36
37
38
39
40
41
42
43
44
45
46
47
48
import {test} from 'tap';
import flatFilter from './index.js';
test('unist-util-flat-filter', (test) => {
test.doesNotThrow(() => {
const tree = {
type: 'root',
children: [
{
type: 'node',
children: [{type: 'leaf', value: '1'}]
},
{type: 'leaf', value: '2'}
]
};
test.deepEqual(
flatFilter(tree, (node) => node.type === 'leaf'),
{
type: 'root',
children: [
{type: 'leaf', value: '1'},
{type: 'leaf', value: '2'}
]
}
);
}, 'filters flatly');
test.doesNotThrow(() => {
const tree = {
type: 'root',
children: [
{
type: 'node',
children: [{type: 'leaf', value: '1'}]
},
{type: 'leaf', value: '2'}
]
};
test.equal(
flatFilter(tree, (node) => node.type === 'test'),
null
);
}, 'returns null when no results');
test.end();
});