fix: Statistic show -0 (#22950)

This commit is contained in:
二货机器人 2020-04-06 11:19:44 +08:00 committed by GitHub
parent 69daa6fea7
commit 5c4db907c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -20,7 +20,7 @@ const StatisticNumber: React.FC<NumberProps> = props => {
const cells = val.match(/^(-?)(\d*)(\.(\d+))?$/);
// Process if illegal number
if (!cells) {
if (!cells || val === '-') {
valueNode = val;
} else {
const negative = cells[1];

View File

@ -21,6 +21,11 @@ describe('Statistic', () => {
MockDate.reset();
});
it('`-` is not a number', () => {
const wrapper = mount(<Statistic value="-" />);
expect(wrapper.find('.ant-statistic-content').text()).toEqual('-');
});
it('customize formatter', () => {
const formatter = jest.fn(() => 93);
const wrapper = mount(<Statistic value={1128} formatter={formatter} />);
@ -47,12 +52,7 @@ describe('Statistic', () => {
describe('Countdown', () => {
it('render correctly', () => {
const now = moment()
.add(2, 'd')
.add(11, 'h')
.add(28, 'm')
.add(9, 's')
.add(3, 'ms');
const now = moment().add(2, 'd').add(11, 'h').add(28, 'm').add(9, 's').add(3, 'ms');
[
['H:m:s', '59:28:9'],