fix(runtime-core): renderList with default value when source is undefined (#498)

This commit is contained in:
Gabriel Loiácono 2019-11-26 23:00:32 -03:00 committed by Evan You
parent bb39910e8e
commit d4f4c7c4d4
2 changed files with 9 additions and 1 deletions

View File

@ -41,4 +41,10 @@ describe('renderList', () => {
renderList(iterable(), (item, index) => `node ${index}: ${item}`) renderList(iterable(), (item, index) => `node ${index}: ${item}`)
).toEqual(['node 0: 1', 'node 1: 2', 'node 2: 3']) ).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([])
})
}) })

View File

@ -31,6 +31,8 @@ export function renderList(
ret[i] = renderItem(source[key], key, i) ret[i] = renderItem(source[key], key, i)
} }
} }
} else {
ret = []
} }
return ret! return ret
} }