Browse Source

test: increase test cov for Layout and Typography (#23407)

pull/23416/head
偏右 5 years ago
committed by GitHub
parent
commit
fc98ab7222
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      components/layout/Sider.tsx
  2. 20
      components/layout/__tests__/index.test.js
  3. 17
      components/typography/Typography.tsx

6
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<InternalSideProps, SiderState> {
}
if (this.props.siderHook) {
console.log('removeSider');
this.props.siderHook.removeSider(this.uniqueId);
}
}
@ -156,10 +156,6 @@ class InternalSider extends React.Component<InternalSideProps, SiderState> {
this.setCollapsed(collapsed, 'clickTrigger');
};
belowShowChange = () => {
this.setState(({ belowShow }) => ({ belowShow: !belowShow }));
};
renderSider = ({ getPrefixCls }: ConfigConsumerProps) => {
const {
prefixCls: customizePrefixCls,

20
components/layout/__tests__/index.test.js

@ -12,6 +12,12 @@ describe('Layout', () => {
mountTest(Layout);
mountTest(Content);
mountTest(Sider);
mountTest(() => (
<Layout>
<Sider />
<Content />
</Layout>
));
rtlTest(Layout);
rtlTest(Content);
@ -60,18 +66,8 @@ describe('Layout', () => {
<Content>Content</Content>
</Layout>,
);
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 () => {

17
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<TypographyProps, {}> {
state = {};
render() {
return <Typography {...this.props} />;
}
}
RefTypography = TypographyWrapper;
}
RefTypography.displayName = 'Typography';
// es default export should use const instead of let
const ExportTypography = (RefTypography as unknown) as React.FC<TypographyProps>;

Loading…
Cancel
Save