From bf487d70ee835d4aa28bb9a90c546b3f2a28318e Mon Sep 17 00:00:00 2001 From: Andrii Kostenko Date: Mon, 14 Jan 2019 23:59:33 +0300 Subject: [PATCH] fix(list): Support null as a child element for ListItem (#584) --- packages/list/ListItem.tsx | 2 +- test/unit/list/ListItem.test.tsx | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/list/ListItem.tsx b/packages/list/ListItem.tsx index 2c8750982..4ed892082 100644 --- a/packages/list/ListItem.tsx +++ b/packages/list/ListItem.tsx @@ -137,7 +137,7 @@ export default class ListItem extends React.Componen } renderChild = (child: React.ReactChild) => { - if (typeof child === 'string' || typeof child === 'number') { + if (typeof child === 'string' || typeof child === 'number' || child === null) { return child; } diff --git a/test/unit/list/ListItem.test.tsx b/test/unit/list/ListItem.test.tsx index 1ed952d1f..23d601dfa 100644 --- a/test/unit/list/ListItem.test.tsx +++ b/test/unit/list/ListItem.test.tsx @@ -74,6 +74,16 @@ test('renders a list item with default tag', () => { assert.equal(wrapper.type(), 'li'); }); +test('renders a list item with text content', () => { + const wrapper = shallow(Test); + assert.equal(wrapper.type(), 'li'); +}); + +test('renders a list item with null as a child', () => { + const wrapper = shallow(
Test
{null}
); + assert.equal(wrapper.type(), 'li'); +}); + test('renders a list item with an anchor tag', () => { const wrapper = shallow(
Test
); assert.equal(wrapper.type(), 'a');