Skip to content

Commit

Permalink
fix: Descriptions warning should work as expect (#16819)
Browse files Browse the repository at this point in the history
* fix warning

* add MockDate
  • Loading branch information
zombieJ authored May 27, 2019
1 parent 6853402 commit 29ec272
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
28 changes: 28 additions & 0 deletions components/descriptions/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import MockDate from 'mockdate';
import { mount } from 'enzyme';
import Descriptions from '..';

Expand All @@ -23,6 +24,17 @@ jest.mock('enquire.js', () => {
});

describe('Descriptions', () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});

afterEach(() => {
MockDate.reset();
errorSpy.mockReset();
});

afterAll(() => {
errorSpy.mockRestore();
});

it('when max-width: 575px,column=1', () => {
// eslint-disable-next-line global-require
const enquire = require('enquire.js');
Expand Down Expand Up @@ -83,4 +95,20 @@ describe('Descriptions', () => {
expect(wrapper.instance().getColumn()).toBe(8);
wrapper.unmount();
});

it('warning if ecceed the row span', () => {
mount(
<Descriptions column={3}>
<DescriptionsItem label="Product" span={2}>
Cloud Database
</DescriptionsItem>
<DescriptionsItem label="Billing" span={2}>
Prepaid
</DescriptionsItem>
</Descriptions>,
);
expect(errorSpy).toHaveBeenCalledWith(
'Warning: [antd: Descriptions] Sum of column `span` in a line exceeds `column` of Descriptions.',
);
});
});
9 changes: 5 additions & 4 deletions components/descriptions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ const generateChildrenRows = (
totalRowSpan += 1;
}
if (totalRowSpan >= column) {
childrenArray.push(columnArray);
columnArray = [];
totalRowSpan = 0;
warning(
totalRowSpan > column,
totalRowSpan <= column,
'Descriptions',
'Sum of column `span` in a line exceeds `column` of Descriptions.',
);

childrenArray.push(columnArray);
columnArray = [];
totalRowSpan = 0;
}
});
if (columnArray.length > 0) {
Expand Down

0 comments on commit 29ec272

Please sign in to comment.