diff --git a/components/skeleton/Skeleton.tsx b/components/skeleton/Skeleton.tsx index 6fcc736e4b95..d3f258ea3f99 100644 --- a/components/skeleton/Skeleton.tsx +++ b/components/skeleton/Skeleton.tsx @@ -161,7 +161,7 @@ const Skeleton = (props: SkeletonProps) => { ); } - return children as React.ReactElement; + return children ? children as React.ReactElement : null; }; Skeleton.defaultProps = { diff --git a/components/skeleton/__tests__/index.test.js b/components/skeleton/__tests__/index.test.js index 1fbbeefd2cda..02b965462c10 100644 --- a/components/skeleton/__tests__/index.test.js +++ b/components/skeleton/__tests__/index.test.js @@ -34,6 +34,11 @@ describe('Skeleton', () => { expect(wrapperSmall.render()).toMatchSnapshot(); }); + it('should display without children', () => { + const wrapper = mount(); + expect(wrapper.render()).toMatchSnapshot(); + }); + it('should display children', () => { const wrapper = mount({[1, 2, 3]}); expect(wrapper.text()).toBe('123');