build(docs-infra): include directives etc in class descendants lists (#25768)

PR Close #25768
This commit is contained in:
Pete Bacon Darwin
2018-09-20 12:58:10 +01:00
committed by Alex Rickabaugh
parent ce06a75ebf
commit 15dadb92ef
6 changed files with 40 additions and 12 deletions

View File

@ -3,7 +3,12 @@ module.exports = function filterBy() {
name: 'filterByPropertyValue',
process: function(list, property, value) {
if (!list) return list;
return list.filter(item => item[property] === value);
const values = Array.isArray(value) ? value : [value];
return list.filter(item => values.some(value => compare(item[property], value)));
}
};
};
};
function compare(actual, expected) {
return expected instanceof(RegExp) ? expected.test(actual) : actual === expected;
}

View File

@ -7,8 +7,19 @@ describe('filterByPropertyValue filter', () => {
it('should be called "filterByPropertyValue"', function() { expect(filter.name).toEqual('filterByPropertyValue'); });
it('should filter out items that do not match the given property value', function() {
it('should filter out items that do not match the given property string value', function() {
expect(filter.process([{ a: 1 }, { a: 2 }, { b: 1 }, { a: 1, b: 2 }, { a: null }, { a: undefined }], 'a', 1))
.toEqual([{ a: 1 }, { a: 1, b: 2 }]);
});
it('should filter out items that do not match the given property regex value', function() {
expect(filter.process([{ a: '1' }, { a: '12' }, { b: '1' }, { a: 'a' }, { a: '1', b: '2' }, { a: null }, { a: undefined }], 'a', /\d/))
.toEqual([{ a: '1' }, { a: '12' }, { a: '1', b: '2' }]);
});
it('should filter out items that do not match the given array of property regex/string values', function() {
expect(filter.process([{ a: '1' }, { a: '12' }, { b: '1' }, { a: 'a' }, { a: '1', b: '2' }, { a: null }, { a: undefined }], 'a', [/\d/, 'a']))
.toEqual([{ a: '1' }, { a: '12' }, { a: 'a' }, { a: '1', b: '2' }]);
});
});