Skip to content

Commit a1a78ef

Browse files
committed
chore: Prettier test code
1 parent 36e2028 commit a1a78ef

File tree

4 files changed

+32
-66
lines changed

4 files changed

+32
-66
lines changed

tests/generate.spec.tsx

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,17 @@ describe('Picker.Generate', () => {
4242
date = generateConfig.setMinute(date, 3);
4343
date = generateConfig.setSecond(date, 5);
4444

45-
expect(
46-
generateConfig.locale.format('en_US', date, 'YYYY-MM-DD HH:mm:ss'),
47-
).toEqual('2020-10-23 02:03:05');
45+
expect(generateConfig.locale.format('en_US', date, 'YYYY-MM-DD HH:mm:ss')).toEqual(
46+
'2020-10-23 02:03:05',
47+
);
4848
});
4949

5050
it('add', () => {
5151
let date = generateConfig.getNow();
5252
date = generateConfig.addYear(date, 2);
5353
date = generateConfig.addMonth(date, 2);
5454
date = generateConfig.addDate(date, 2);
55-
expect(
56-
generateConfig.locale.format('en_US', date, 'YYYY-MM-DD'),
57-
).toEqual('1992-11-05');
55+
expect(generateConfig.locale.format('en_US', date, 'YYYY-MM-DD')).toEqual('1992-11-05');
5856
});
5957

6058
it('isAfter', () => {
@@ -73,14 +71,11 @@ describe('Picker.Generate', () => {
7371
describe('parse', () => {
7472
it('basic', () => {
7573
['2000-01-02', '02/01/2000'].forEach(str => {
76-
const date = generateConfig.locale.parse('en_US', str, [
77-
'YYYY-MM-DD',
78-
'DD/MM/YYYY',
79-
]);
80-
81-
expect(
82-
generateConfig.locale.format('en_US', date!, 'YYYY-MM-DD'),
83-
).toEqual('2000-01-02');
74+
const date = generateConfig.locale.parse('en_US', str, ['YYYY-MM-DD', 'DD/MM/YYYY']);
75+
76+
expect(generateConfig.locale.format('en_US', date!, 'YYYY-MM-DD')).toEqual(
77+
'2000-01-02',
78+
);
8479
});
8580
});
8681

@@ -107,14 +102,11 @@ describe('Picker.Generate', () => {
107102
describe('locale', () => {
108103
it('parse', () => {
109104
['2000-01-02', '02/01/2000'].forEach(str => {
110-
const date = generateConfig.locale.parse('en_US', str, [
111-
'YYYY-MM-DD',
112-
'DD/MM/YYYY',
113-
]);
105+
const date = generateConfig.locale.parse('en_US', str, ['YYYY-MM-DD', 'DD/MM/YYYY']);
114106

115-
expect(
116-
generateConfig.locale.format('en_US', date!, 'YYYY-MM-DD'),
117-
).toEqual('2000-01-02');
107+
expect(generateConfig.locale.format('en_US', date!, 'YYYY-MM-DD')).toEqual(
108+
'2000-01-02',
109+
);
118110
});
119111
});
120112
});
@@ -127,37 +119,27 @@ describe('Picker.Generate', () => {
127119
['en_US', 'zh_CN'].forEach(() => {
128120
expect(
129121
generateConfig.getWeekDay(
130-
generateConfig.locale.parse('en_US', '2000-01-01', [
131-
'YYYY-MM-DD',
132-
])!,
122+
generateConfig.locale.parse('en_US', '2000-01-01', ['YYYY-MM-DD'])!,
133123
),
134124
).toEqual(6);
135125
});
136126
});
137127

138128
it('Parse format Wo', () => {
139129
expect(
140-
generateConfig.locale
141-
.parse('en_US', '2012-51st', ['YYYY-Wo'])
142-
?.format('Wo'),
130+
generateConfig.locale.parse('en_US', '2012-51st', ['YYYY-Wo'])?.format('Wo'),
143131
).toEqual('51st');
144-
expect(
145-
generateConfig.locale
146-
.parse('zh_CN', '2012-1周', ['YYYY-Wo'])
147-
?.format('Wo'),
148-
).toEqual('1周');
132+
expect(generateConfig.locale.parse('zh_CN', '2012-1周', ['YYYY-Wo'])?.format('Wo')).toEqual(
133+
'1周',
134+
);
149135
});
150136

151137
it('Parse format faild', () => {
138+
expect(generateConfig.locale.parse('en_US', 'invalid string', ['invalid string'])).toEqual(
139+
null,
140+
);
152141
expect(
153-
generateConfig.locale.parse('en_US', 'invalid string', [
154-
'invalid string',
155-
]),
156-
).toEqual(null);
157-
expect(
158-
generateConfig.locale.parse('en_US', 'invalid string', [
159-
'invalid string-Wo',
160-
]),
142+
generateConfig.locale.parse('en_US', 'invalid string', ['invalid string-Wo']),
161143
).toEqual(null);
162144
});
163145

tests/panel.spec.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ describe('Picker.Panel', () => {
6969
expect(wrapper.find('.rc-picker-year-panel').length).toBeTruthy();
7070
});
7171

72-
[['month', 'Aug'], ['quarter', 'Q3']].forEach(([picker, cell]) => {
72+
[
73+
['month', 'Aug'],
74+
['quarter', 'Q3'],
75+
].forEach(([picker, cell]) => {
7376
it(picker, () => {
7477
const wrapper = mount(<MomentPickerPanel picker={picker as any} />);
7578
wrapper.find('.rc-picker-year-btn').simulate('click');

tests/setup.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ Object.assign(Enzyme.ReactWrapper.prototype, {
2828
},
2929
isOpen() {
3030
const openDiv = this.find('.rc-picker-dropdown').hostNodes();
31-
return (
32-
openDiv &&
33-
openDiv.length &&
34-
!openDiv.hasClass('rc-picker-dropdown-hidden')
35-
);
31+
return openDiv && openDiv.length && !openDiv.hasClass('rc-picker-dropdown-hidden');
3632
},
3733
findCell(text, index = 0) {
3834
let matchCell;
@@ -41,10 +37,7 @@ Object.assign(Enzyme.ReactWrapper.prototype, {
4137
.at(index)
4238
.find('td')
4339
.forEach(td => {
44-
if (
45-
td.text() === String(text) &&
46-
td.props().className.includes('-in-view')
47-
) {
40+
if (td.text() === String(text) && td.props().className.includes('-in-view')) {
4841
matchCell = td;
4942
}
5043
});

tests/util.spec.tsx

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,19 @@ describe('Picker.Util', () => {
1414
// Time is only for time
1515
it('isSameTime', () => {
1616
expect(
17-
isSameTime(
18-
momentGenerateConfig,
19-
getMoment('2000-01-01'),
20-
getMoment('1989-11-28'),
21-
),
17+
isSameTime(momentGenerateConfig, getMoment('2000-01-01'), getMoment('1989-11-28')),
2218
).toBeTruthy();
2319

24-
expect(
25-
isSameTime(momentGenerateConfig, null, getMoment('1989-11-28')),
26-
).toBeFalsy();
20+
expect(isSameTime(momentGenerateConfig, null, getMoment('1989-11-28'))).toBeFalsy();
2721

2822
expect(isSameTime(momentGenerateConfig, null, null)).toBeTruthy();
2923
});
3024

3125
it('isSameDecade', () => {
3226
expect(isSameDecade(momentGenerateConfig, null, null)).toBeTruthy();
27+
expect(isSameDecade(momentGenerateConfig, getMoment('2000-01-02'), null)).toBeFalsy();
3328
expect(
34-
isSameDecade(momentGenerateConfig, getMoment('2000-01-02'), null),
35-
).toBeFalsy();
36-
expect(
37-
isSameDecade(
38-
momentGenerateConfig,
39-
getMoment('1995-01-01'),
40-
getMoment('1999-01-01'),
41-
),
29+
isSameDecade(momentGenerateConfig, getMoment('1995-01-01'), getMoment('1999-01-01')),
4230
).toBeTruthy();
4331
});
4432
});

0 commit comments

Comments
 (0)