@@ -81,34 +81,63 @@ describe('formatDate', () => {
81
81
} )
82
82
83
83
describe ( 'isDateInvalid' , ( ) => {
84
- it ( 'returns false if the date is within the min & max' , ( ) => {
85
- const testMin = new Date ( 'May 1, 1988' )
86
- const testMax = new Date ( 'June 1, 1988' )
87
- expect ( isDateInvalid ( '05/16/1988' , testMin , testMax ) ) . toEqual ( false )
88
- } )
89
-
90
- it ( 'returns true if the date is not within the min & max' , ( ) => {
91
- const testMin = new Date ( 'May 1, 1988' )
92
- const testMax = new Date ( 'June 1, 1988' )
93
- expect ( isDateInvalid ( '08/16/1988' , testMin , testMax ) ) . toEqual ( true )
94
- } )
95
-
96
- it ( 'returns true if the date is not valid' , ( ) => {
97
- const testMin = new Date ( 'May 1, 1988' )
98
- const testMax = new Date ( 'June 1, 1988' )
99
- expect ( isDateInvalid ( 'not a date' , testMin , testMax ) ) . toEqual ( true )
100
- } )
84
+ it . each ( [
85
+ [ '05/16/1988' , DEFAULT_EXTERNAL_DATE_FORMAT ] ,
86
+ [ '1988-05-16' , INTERNAL_DATE_FORMAT ] ,
87
+ ] as const ) (
88
+ 'returns false if the date is within the min & max' ,
89
+ ( date , format ) => {
90
+ const testMin = new Date ( 'May 1, 1988' )
91
+ const testMax = new Date ( 'June 1, 1988' )
92
+ expect ( isDateInvalid ( date , format , testMin , testMax ) ) . toEqual ( false )
93
+ }
94
+ )
95
+
96
+ it . each ( [
97
+ [ '08/16/1988' , DEFAULT_EXTERNAL_DATE_FORMAT ] ,
98
+ [ '1988-08-16' , INTERNAL_DATE_FORMAT ] ,
99
+ ] as const ) (
100
+ 'returns true if the date is not within the min & max' ,
101
+ ( date , format ) => {
102
+ const testMin = new Date ( 'May 1, 1988' )
103
+ const testMax = new Date ( 'June 1, 1988' )
104
+ expect ( isDateInvalid ( date , format , testMin , testMax ) ) . toEqual ( true )
105
+ }
106
+ )
107
+
108
+ it . each ( [ DEFAULT_EXTERNAL_DATE_FORMAT , INTERNAL_DATE_FORMAT ] as const ) (
109
+ 'returns true if the date is not valid' ,
110
+ ( format ) => {
111
+ const testMin = new Date ( 'May 1, 1988' )
112
+ const testMax = new Date ( 'June 1, 1988' )
113
+ expect ( isDateInvalid ( 'not a date' , format , testMin , testMax ) ) . toEqual (
114
+ true
115
+ )
116
+ }
117
+ )
101
118
102
119
describe ( 'with no max date' , ( ) => {
103
- it ( 'returns false if the date is after the min' , ( ) => {
104
- const testMin = new Date ( 'May 1, 1988' )
105
- expect ( isDateInvalid ( '05/16/1988' , testMin ) ) . toEqual ( false )
106
- } )
120
+ it . each ( [
121
+ [ '05/16/1988' , DEFAULT_EXTERNAL_DATE_FORMAT ] ,
122
+ [ '1988-05-16' , INTERNAL_DATE_FORMAT ] ,
123
+ ] as const ) (
124
+ 'returns false if the date is after the min' ,
125
+ ( date , format ) => {
126
+ const testMin = new Date ( 'May 1, 1988' )
127
+ expect ( isDateInvalid ( date , format , testMin ) ) . toEqual ( false )
128
+ }
129
+ )
107
130
108
- it ( 'returns true if the date is not after the min' , ( ) => {
109
- const testMin = new Date ( 'May 1, 1988' )
110
- expect ( isDateInvalid ( '02/16/1988' , testMin ) ) . toEqual ( true )
111
- } )
131
+ it . each ( [
132
+ [ '02/16/1988' , DEFAULT_EXTERNAL_DATE_FORMAT ] ,
133
+ [ '1988-02-16' , INTERNAL_DATE_FORMAT ] ,
134
+ ] as const ) (
135
+ 'returns true if the date is not after the min' ,
136
+ ( date , format ) => {
137
+ const testMin = new Date ( 'May 1, 1988' )
138
+ expect ( isDateInvalid ( date , format , testMin ) ) . toEqual ( true )
139
+ }
140
+ )
112
141
} )
113
142
} )
114
143
0 commit comments