|
1 | 1 | import{DateToDay}from'../DateToDay' |
2 | 2 |
|
3 | | -test('The date 18/02/2001 is Sunday',()=>{ |
4 | | -constres=DateToDay('18/02/2001') |
5 | | -expect(res).toBe('Sunday') |
6 | | -}) |
7 | | - |
8 | | -test('The date 18/12/2020 is Friday',()=>{ |
9 | | -constres=DateToDay('18/12/2020') |
10 | | -expect(res).toBe('Friday') |
11 | | -}) |
| 3 | +describe('DateToDay',()=>{ |
| 4 | +it.each([ |
| 5 | +['18/02/2001','Sunday'], |
| 6 | +['18/12/2020','Friday'], |
| 7 | +['12/12/2012','Wednesday'], |
| 8 | +['01/01/2001','Monday'], |
| 9 | +['1/1/2020','Wednesday'], |
| 10 | +['2/3/2014','Sunday'], |
| 11 | +['28/2/2017','Tuesday'], |
| 12 | +['02/03/2024','Saturday'], |
| 13 | +['29/02/2024','Thursday'] |
| 14 | +])('%s is %s',(date,day)=>{ |
| 15 | +expect(DateToDay(date)).toBe(day) |
| 16 | +}) |
12 | 17 |
|
13 | | -test('The date 12/12/2012 is Wednesday',()=>{ |
14 | | -constres=DateToDay('12/12/2012') |
15 | | -expect(res).toBe('Wednesday') |
16 | | -}) |
17 | | -test('The date 01/01/2001 is Monday',()=>{ |
18 | | -constres=DateToDay('01/01/2001') |
19 | | -expect(res).toBe('Monday') |
20 | | -}) |
21 | | - |
22 | | -test('The date 1/1/2020 is Wednesday',()=>{ |
23 | | -constres=DateToDay('1/1/2020') |
24 | | -expect(res).toBe('Wednesday') |
25 | | -}) |
26 | | - |
27 | | -test('The date 2/3/2014 is Sunday',()=>{ |
28 | | -constres=DateToDay('2/3/2014') |
29 | | -expect(res).toBe('Sunday') |
30 | | -}) |
| 18 | +it('should throw when input is not a string',()=>{ |
| 19 | +expect(()=>DateToDay(100)).toThrowError() |
| 20 | +}) |
31 | 21 |
|
32 | | -test('The date 28/2/2017 is Tuesday',()=>{ |
33 | | -constres=DateToDay('28/2/2017') |
34 | | -expect(res).toBe('Tuesday') |
| 22 | +it.each(['32/01/2000','00/01/2000','15/00/2000','15/13/2000'])( |
| 23 | +'should throw when input is not a correct date %s', |
| 24 | +(wrongDate)=>{ |
| 25 | +expect(()=>DateToDay(wrongDate)).toThrowError() |
| 26 | +} |
| 27 | +) |
35 | 28 | }) |
0 commit comments