From 06ef9117671347e0cdb9571a9e18ce7d1ae79267 Mon Sep 17 00:00:00 2001 From: Pedro Lemos <33739457+Leinvedan@users.noreply.github.com> Date: Wed, 12 Jan 2022 18:52:07 -0300 Subject: [PATCH] fix(struct): handle empty listValue (#16) --- index.ts | 2 +- test.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 9f37329..cfb0fbc 100644 --- a/index.ts +++ b/index.ts @@ -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); } }; diff --git a/test.ts b/test.ts index 774d502..9f215e3 100644 --- a/test.ts +++ b/test.ts @@ -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: []}); +});