diff --git a/packages/runtime-core/__tests__/helpers/renderList.spec.ts b/packages/runtime-core/__tests__/helpers/renderList.spec.ts index d55bffbd..e28c6a00 100644 --- a/packages/runtime-core/__tests__/helpers/renderList.spec.ts +++ b/packages/runtime-core/__tests__/helpers/renderList.spec.ts @@ -41,4 +41,10 @@ describe('renderList', () => { renderList(iterable(), (item, index) => `node ${index}: ${item}`) ).toEqual(['node 0: 1', 'node 1: 2', 'node 2: 3']) }) + + it('should return empty array when source is undefined', () => { + expect( + renderList(undefined, (item, index) => `node ${index}: ${item}`) + ).toEqual([]) + }) }) diff --git a/packages/runtime-core/src/helpers/renderList.ts b/packages/runtime-core/src/helpers/renderList.ts index 693c87bc..f45020d4 100644 --- a/packages/runtime-core/src/helpers/renderList.ts +++ b/packages/runtime-core/src/helpers/renderList.ts @@ -31,6 +31,8 @@ export function renderList( ret[i] = renderItem(source[key], key, i) } } + } else { + ret = [] } - return ret! + return ret }