makeLookup: Allow for key of zero

This commit is contained in:
Scott Nonnenberg 2021-01-27 14:39:45 -08:00 committed by GitHub
parent a769402c0c
commit 12c44d40a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 3 deletions

View file

@ -33,13 +33,24 @@ describe('makeLookup', () => {
});
});
it('ignores falsy properties', () => {
const arr = [{}, { foo: '' }, { foo: false }, { foo: null }];
it('ignores undefined properties', () => {
const arr = [{}, { foo: undefined }];
const result = makeLookup(arr, 'foo');
assert.deepEqual(result, {});
});
it('allows key of 0', () => {
const arr = [{}, { id: 0 }, { id: 1 }, { id: 2 }];
const result = makeLookup(arr, 'id');
assert.deepEqual(result, {
0: { id: 0 },
1: { id: 1 },
2: { id: 2 },
});
});
it('converts the lookup to a string', () => {
const arr = [
{ foo: 'bar' },