Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 1cfaf64

Browse files
Foxandxsswesleycho
authored andcommitted
test(dateParser): missing tests, refactorized tests
Closes #4766
1 parent 97c4333 commit 1cfaf64

File tree

1 file changed

+51
-35
lines changed

1 file changed

+51
-35
lines changed

Diff for: src/dateparser/test/dateparser.spec.js

+51-35
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,21 @@ describe('date parser', function() {
2929
expectParse('11-08-13', 'dd-MM-yy', new Date(2013, 7, 11, 0));
3030
});
3131

32-
it('should work correctly for `M`', function() {
33-
expectParse('8/11/2013', 'M/dd/yyyy', new Date(2013, 7, 11, 0));
34-
expectParse('07.11.05', 'dd.M.yy', new Date(2005, 10, 7, 0));
35-
expectParse('02-5-11', 'dd-M-yy', new Date(2011, 4, 2, 0));
36-
expectParse('2/05/1980', 'M/dd/yyyy', new Date(1980, 1, 5, 0));
37-
expectParse('1955/2/05', 'yyyy/M/dd', new Date(1955, 1, 5, 0));
38-
expectParse('02-5-11', 'dd-M-yy', new Date(2011, 4, 2, 0));
32+
it('should work correctly for `y`', function() {
33+
expectParse('17.11.2013', 'dd.MM.y', new Date(2013, 10, 17, 0));
34+
expectParse('31.12.2013', 'dd.MM.y', new Date(2013, 11, 31, 0));
35+
expectParse('08-03-1991', 'dd-MM-y', new Date(1991, 2, 8, 0));
36+
expectParse('03/05/1980', 'MM/dd/y', new Date(1980, 2, 5, 0));
37+
expectParse('10.01/1983', 'dd.MM/y', new Date(1983, 0, 10, 0));
38+
expectParse('11-09-1980', 'MM-dd-y', new Date(1980, 10, 9, 0));
39+
expectParse('2011/02/05', 'y/MM/dd', new Date(2011, 1, 5, 0));
40+
});
41+
42+
it('should work correctly for `MMMM`', function() {
43+
expectParse('17.November.13', 'dd.MMMM.yy', new Date(2013, 10, 17, 0));
44+
expectParse('05-March-1980', 'dd-MMMM-yyyy', new Date(1980, 2, 5, 0));
45+
expectParse('February/05/1980', 'MMMM/dd/yyyy', new Date(1980, 1, 5, 0));
46+
expectParse('1949/December/20', 'yyyy/MMMM/dd', new Date(1949, 11, 20, 0));
3947
});
4048

4149
it('should work correctly for `MMM`', function() {
@@ -45,11 +53,13 @@ describe('date parser', function() {
4553
expectParse('1955/Feb/05', 'yyyy/MMM/dd', new Date(1955, 1, 5, 0));
4654
});
4755

48-
it('should work correctly for `MMMM`', function() {
49-
expectParse('17.November.13', 'dd.MMMM.yy', new Date(2013, 10, 17, 0));
50-
expectParse('05-March-1980', 'dd-MMMM-yyyy', new Date(1980, 2, 5, 0));
51-
expectParse('February/05/1980', 'MMMM/dd/yyyy', new Date(1980, 1, 5, 0));
52-
expectParse('1949/December/20', 'yyyy/MMMM/dd', new Date(1949, 11, 20, 0));
56+
it('should work correctly for `M`', function() {
57+
expectParse('8/11/2013', 'M/dd/yyyy', new Date(2013, 7, 11, 0));
58+
expectParse('07.11.05', 'dd.M.yy', new Date(2005, 10, 7, 0));
59+
expectParse('02-5-11', 'dd-M-yy', new Date(2011, 4, 2, 0));
60+
expectParse('2/05/1980', 'M/dd/yyyy', new Date(1980, 1, 5, 0));
61+
expectParse('1955/2/05', 'yyyy/M/dd', new Date(1955, 1, 5, 0));
62+
expectParse('02-5-11', 'dd-M-yy', new Date(2011, 4, 2, 0));
5363
});
5464

5565
it('should work correctly for `d`', function() {
@@ -60,6 +70,20 @@ describe('date parser', function() {
6070
expectParse('11-08-13', 'd-MM-yy', new Date(2013, 7, 11, 0));
6171
});
6272

73+
it('should work correctly for `EEEE`', function() {
74+
expectParse('Sunday.17.November.13', 'EEEE.d.MMMM.yy', new Date(2013, 10, 17, 0));
75+
expectParse('8-Friday-March-1991', 'd-EEEE-MMMM-yyyy', new Date(1991, 2, 8, 0));
76+
expectParse('February/5/1980/Tuesday', 'MMMM/d/yyyy/EEEE', new Date(1980, 1, 5, 0));
77+
expectParse('1955/Saturday/February/5', 'yyyy/EEEE/MMMM/d', new Date(1955, 1, 5, 0));
78+
});
79+
80+
it('should work correctly for `EEE`', function() {
81+
expectParse('Sun.17.November.13', 'EEE.d.MMMM.yy', new Date(2013, 10, 17, 0));
82+
expectParse('8-Fri-March-1991', 'd-EEE-MMMM-yyyy', new Date(1991, 2, 8, 0));
83+
expectParse('February/5/1980/Tue', 'MMMM/d/yyyy/EEE', new Date(1980, 1, 5, 0));
84+
expectParse('1955/Sat/February/5', 'yyyy/EEE/MMMM/d', new Date(1955, 1, 5, 0));
85+
});
86+
6387
it('should work correctly for `HH`', function() {
6488
expectParse('22.March.15.22', 'd.MMMM.yy.HH', new Date(2015, 2, 22, 22));
6589
expectParse('8-March-1991-11', 'd-MMMM-yyyy-HH', new Date(1991, 2, 8, 11));
@@ -68,6 +92,14 @@ describe('date parser', function() {
6892
expectParse('11-08-13 23', 'd-MM-yy HH', new Date(2013, 7, 11, 23));
6993
});
7094

95+
it('should work correctly for `H`', function() {
96+
expectParse('22.March.15.22', 'd.MMMM.yy.H', new Date(2015, 2, 22, 22));
97+
expectParse('8-March-1991-11', 'd-MMMM-yyyy-H', new Date(1991, 2, 8, 11));
98+
expectParse('February/5/1980/0', 'MMMM/d/yyyy/H', new Date(1980, 1, 5, 0));
99+
expectParse('1955/February/5 3', 'yyyy/MMMM/d H', new Date(1955, 1, 5, 3));
100+
expectParse('11-08-13 23', 'd-MM-yy H', new Date(2013, 7, 11, 23));
101+
});
102+
71103
it('should work correctly for `hh`', function() {
72104
expectParse('22.March.15.22', 'd.MMMM.yy.hh', undefined);
73105
expectParse('22.March.15.12', 'd.MMMM.yy.hh', new Date(2015, 2, 22, 12));
@@ -78,14 +110,6 @@ describe('date parser', function() {
78110
expectParse('11-08-13 09', 'd-MM-yy hh', new Date(2013, 7, 11, 9));
79111
});
80112

81-
it('should work correctly for `H`', function() {
82-
expectParse('22.March.15.22', 'd.MMMM.yy.H', new Date(2015, 2, 22, 22));
83-
expectParse('8-March-1991-11', 'd-MMMM-yyyy-H', new Date(1991, 2, 8, 11));
84-
expectParse('February/5/1980/0', 'MMMM/d/yyyy/H', new Date(1980, 1, 5, 0));
85-
expectParse('1955/February/5 3', 'yyyy/MMMM/d H', new Date(1955, 1, 5, 3));
86-
expectParse('11-08-13 23', 'd-MM-yy H', new Date(2013, 7, 11, 23));
87-
});
88-
89113
it('should work correctly for `h`', function() {
90114
expectParse('22.March.15.12', 'd.MMMM.yy.h', new Date(2015, 2, 22, 12));
91115
expectParse('8-March-1991-11', 'd-MMMM-yyyy-h', new Date(1991, 2, 8, 11));
@@ -178,39 +202,31 @@ describe('date parser', function() {
178202

179203
describe('with edge case', function() {
180204
it('should not work for invalid number of days in February', function() {
181-
expect(dateParser.parse('29.02.2013', 'dd.MM.yyyy')).toBeUndefined();
205+
expectParse('29.02.2013', 'dd.MM.yyyy', undefined);
182206
});
183207

184208
it('should not work for 0 number of days', function() {
185-
expect(dateParser.parse('00.02.2013', 'dd.MM.yyyy')).toBeUndefined();
209+
expectParse('00.02.2013', 'dd.MM.yyyy', undefined);
186210
});
187211

188212
it('should work for 29 days in February for leap years', function() {
189213
expectParse('29.02.2000', 'dd.MM.yyyy', new Date(2000, 1, 29, 0));
190214
});
191215

192216
it('should not work for 31 days for some months', function() {
193-
expect(dateParser.parse('31-04-2013', 'dd-MM-yyyy')).toBeUndefined();
194-
expect(dateParser.parse('November 31, 2013', 'MMMM d, yyyy')).toBeUndefined();
195-
});
196-
197-
it('should work when base date is a string', function() {
198-
expect(dateParser.parse('01-02-2034', 'dd-MM-yyyy', '05-06-2078')).toEqual(new Date(2034, 1, 1));
199-
});
200-
201-
it('should work when base date is an invalid date', function() {
202-
expect(dateParser.parse('30-12-2015', 'dd-MM-yyyy', new Date('foo'))).toEqual(new Date(2015, 11, 30));
217+
expectParse('31-04-2013', 'dd-MM-yyyy', undefined);
218+
expectParse('November 31, 2013', 'MMMM d, yyyy', undefined);
203219
});
204220
});
205221

206222
it('should not parse non-string inputs', function() {
207-
expect(dateParser.parse(123456, 'dd.MM.yyyy')).toBe(123456);
223+
expectParse(123456, 'dd.MM.yyyy', 123456);
208224
var date = new Date();
209-
expect(dateParser.parse(date, 'dd.MM.yyyy')).toBe(date);
225+
expectParse(date, 'dd.MM.yyyy', date);
210226
});
211227

212228
it('should not parse if no format is specified', function() {
213-
expect(dateParser.parse('21.08.1951', '')).toBe('21.08.1951');
229+
expectParse('21.08.1951', '', '21.08.1951');
214230
});
215231

216232
it('should reinitialize when locale changes', inject(function($locale) {

0 commit comments

Comments
 (0)