fix: skeleton cannot dispaly without children

This commit is contained in:
AlbertAZ1992 2022-04-06 11:42:38 +08:00
parent a67c0d28d3
commit 0b4a9682f9
2 changed files with 6 additions and 1 deletions

View File

@ -161,7 +161,7 @@ const Skeleton = (props: SkeletonProps) => {
</div>
);
}
return children as React.ReactElement;
return children ? children as React.ReactElement : null;
};
Skeleton.defaultProps = {

View File

@ -34,6 +34,11 @@ describe('Skeleton', () => {
expect(wrapperSmall.render()).toMatchSnapshot();
});
it('should display without children', () => {
const wrapper = mount(<Skeleton loading={false}></Skeleton>);
expect(wrapper.render()).toMatchSnapshot();
});
it('should display children', () => {
const wrapper = mount(<Skeleton loading={false}>{[1, 2, 3]}</Skeleton>);
expect(wrapper.text()).toBe('123');