allow custom functions in filters
This commit is contained in:
@ -252,3 +252,30 @@ test ('recursive filter carry field', (t) => {
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
test ('recursive filter custom function', (t) => {
|
||||
const to_filter = [
|
||||
{
|
||||
name: 'foo',
|
||||
children: [
|
||||
{ name: 'bar' },
|
||||
{ name: 'baz' },
|
||||
{ foo: 'bar' }
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
const res = util.recursive_filter (
|
||||
to_filter,
|
||||
[ { function: (elem) => elem.name === 'foo bar' } ],
|
||||
'children',
|
||||
[ 'name' ]
|
||||
);
|
||||
|
||||
t.deepEqual (res, [
|
||||
{
|
||||
name: 'foo',
|
||||
children: [ { name: 'bar' } ]
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
Reference in New Issue
Block a user