Skip to content

Commit

Permalink
fix(struct): handle empty listValue (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
fontelemos authored Jan 12, 2022
1 parent 3b74d29 commit 06ef911
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export const list = {
* @param {ListValue} list the protobuf list value.
* @returns {Array.<*>}
*/
decode({values}: ListValue): JsonArray {
decode({values = []}: ListValue): JsonArray {
return values.map(value.decode);
}
};
5 changes: 5 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,8 @@ test('struct.decode - undefined fields', t => {
const actual = struct.decode({});
t.deepEqual(actual, {});
});

test('struct.decode - empty listValue', t => {
const actual = struct.decode({ fields: { test: { listValue: {} } } });
t.deepEqual(actual, {test: []});
});

0 comments on commit 06ef911

Please sign in to comment.