From fc98ab722269d77a048392916284736a625f919c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=81=8F=E5=8F=B3?= Date: Mon, 20 Apr 2020 19:18:53 +0800 Subject: [PATCH] test: increase test cov for Layout and Typography (#23407) --- components/layout/Sider.tsx | 6 +----- components/layout/__tests__/index.test.js | 20 ++++++++------------ components/typography/Typography.tsx | 17 ++--------------- 3 files changed, 11 insertions(+), 32 deletions(-) diff --git a/components/layout/Sider.tsx b/components/layout/Sider.tsx index 31e52f8088..a50e4ff2fd 100644 --- a/components/layout/Sider.tsx +++ b/components/layout/Sider.tsx @@ -50,7 +50,6 @@ type InternalSideProps = SiderProps & LayoutContextProps; export interface SiderState { collapsed?: boolean; below: boolean; - belowShow?: boolean; } const generateId = (() => { @@ -124,6 +123,7 @@ class InternalSider extends React.Component { } if (this.props.siderHook) { + console.log('removeSider'); this.props.siderHook.removeSider(this.uniqueId); } } @@ -156,10 +156,6 @@ class InternalSider extends React.Component { this.setCollapsed(collapsed, 'clickTrigger'); }; - belowShowChange = () => { - this.setState(({ belowShow }) => ({ belowShow: !belowShow })); - }; - renderSider = ({ getPrefixCls }: ConfigConsumerProps) => { const { prefixCls: customizePrefixCls, diff --git a/components/layout/__tests__/index.test.js b/components/layout/__tests__/index.test.js index eb7aef598c..af29040976 100644 --- a/components/layout/__tests__/index.test.js +++ b/components/layout/__tests__/index.test.js @@ -12,6 +12,12 @@ describe('Layout', () => { mountTest(Layout); mountTest(Content); mountTest(Sider); + mountTest(() => ( + + + + + )); rtlTest(Layout); rtlTest(Content); @@ -60,18 +66,8 @@ describe('Layout', () => { Content , ); - expect( - wrapper - .find('.ant-layout-sider') - .at(0) - .prop('style').width, - ).toBe('50%'); - expect( - wrapper - .find('.ant-layout-sider') - .at(0) - .prop('style').flex, - ).toBe('0 0 50%'); + expect(wrapper.find('.ant-layout-sider').at(0).prop('style').width).toBe('50%'); + expect(wrapper.find('.ant-layout-sider').at(0).prop('style').flex).toBe('0 0 50%'); }); it('detect ant-layout-sider-zero-width class in sider when its width is 0%', async () => { diff --git a/components/typography/Typography.tsx b/components/typography/Typography.tsx index cae96f2a20..93478bd9b5 100644 --- a/components/typography/Typography.tsx +++ b/components/typography/Typography.tsx @@ -61,22 +61,9 @@ const Typography: React.RefForwardingComponent<{}, InternalTypographyProps> = ( ); }; -let RefTypography; +const RefTypography = React.forwardRef(Typography); -if (React.forwardRef) { - RefTypography = React.forwardRef(Typography); - RefTypography.displayName = 'Typography'; -} else { - class TypographyWrapper extends React.Component { - state = {}; - - render() { - return ; - } - } - - RefTypography = TypographyWrapper; -} +RefTypography.displayName = 'Typography'; // es default export should use const instead of let const ExportTypography = (RefTypography as unknown) as React.FC;