Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: should not throw error when percent is null #40378

Merged
merged 5 commits into from Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions components/progress/__tests__/index.test.tsx
Expand Up @@ -3,9 +3,9 @@ import type { ProgressProps } from '..';
import Progress from '..';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { render } from '../../../tests/utils';
import { handleGradient, sortGradient } from '../Line';
import ProgressSteps from '../Steps';
import { render } from '../../../tests/utils';

describe('Progress', () => {
mountTest(Progress);
Expand Down Expand Up @@ -240,15 +240,22 @@ describe('Progress', () => {
);
});

// https://github.com/ant-design/ant-design/issues/30685
describe('github issues', () => {
it('"Rendered more hooks than during the previous render"', () => {
// https://github.com/ant-design/ant-design/issues/30685
it('Rendered more hooks than during the previous render', () => {
expect(() => {
const { rerender } = render(
<Progress percent={60} success={{ percent: 0 }} type="circle" />,
);
rerender(<Progress percent={60} success={{ percent: 10 }} type="circle" />);
}).not.toThrow();
});

// https://github.com/ant-design/ant-design/issues/40377
it('should not throw error when percent is null', () => {
expect(() => {
render(<Progress percent={null as unknown as number} />);
}).not.toThrow();
});
});
});
4 changes: 2 additions & 2 deletions components/progress/progress.tsx
Expand Up @@ -11,8 +11,8 @@ import warning from '../_util/warning';
import Circle from './Circle';
import Line from './Line';
import Steps from './Steps';
import { getSuccessPercent, validProgress } from './utils';
import useStyle from './style';
import { getSuccessPercent, validProgress } from './utils';

const ProgressTypes = ['line', 'circle', 'dashboard'] as const;
export type ProgressType = typeof ProgressTypes[number];
Expand Down Expand Up @@ -71,7 +71,7 @@ const Progress: React.FC<ProgressProps> = (props) => {
const percentNumber = React.useMemo<number>(() => {
const successPercent = getSuccessPercent(props);
return parseInt(
successPercent !== undefined ? successPercent.toString() : percent.toString(),
successPercent !== undefined ? (successPercent ?? 0)?.toString() : (percent ?? 0)?.toString(),
li-jia-nan marked this conversation as resolved.
Show resolved Hide resolved
10,
);
}, [percent, props.success, props.successPercent]);
Expand Down