@@ -20,8 +20,8 @@ const Assert = BaseAssert.extend({
20
20
*/
21
21
22
22
describe ( 'DateAssert' , ( ) => {
23
- it ( 'should throw an error if the input value is not a string or a date ' , ( ) => {
24
- const choices = [ [ ] , { } , 123 ] ;
23
+ it ( 'should throw an error if the input value is not a date or a string or a number ' , ( ) => {
24
+ const choices = [ [ ] , { } ] ;
25
25
26
26
choices . forEach ( choice => {
27
27
try {
@@ -30,7 +30,7 @@ describe('DateAssert', () => {
30
30
should . fail ( ) ;
31
31
} catch ( e ) {
32
32
e . should . be . instanceOf ( Violation ) ;
33
- e . violation . value . should . equal ( 'must_be_a_date_or_a_string ' ) ;
33
+ e . violation . value . should . equal ( 'must_be_a_date_or_a_string_or_a_number ' ) ;
34
34
}
35
35
} ) ;
36
36
} ) ;
@@ -61,6 +61,17 @@ describe('DateAssert', () => {
61
61
}
62
62
} ) ;
63
63
64
+ it ( 'should throw an error if the input value is an invalid timestamp' , ( ) => {
65
+ try {
66
+ new Assert ( ) . Date ( ) . validate ( - Number . MAX_VALUE ) ;
67
+
68
+ should . fail ( ) ;
69
+ } catch ( e ) {
70
+ e . should . be . instanceOf ( Violation ) ;
71
+ e . show ( ) . assert . should . equal ( 'Date' ) ;
72
+ }
73
+ } ) ;
74
+
64
75
it ( 'should throw an error if value does not pass strict validation' , ( ) => {
65
76
try {
66
77
new Assert ( ) . Date ( { format : 'YYYY-MM-DD' } ) . validate ( '2000.12.30' ) ;
@@ -82,15 +93,23 @@ describe('DateAssert', () => {
82
93
}
83
94
} ) ;
84
95
85
- it ( 'should accept a `Date`' , ( ) => {
96
+ it ( 'should accept an instance of `Date`' , ( ) => {
86
97
new Assert ( ) . Date ( ) . validate ( new Date ( ) ) ;
87
98
} ) ;
88
99
89
100
it ( 'should accept a correctly formatted date' , ( ) => {
90
101
new Assert ( ) . Date ( { format : 'YYYY-MM-DD' } ) . validate ( '2000-12-30' ) ;
91
102
} ) ;
92
103
93
- it ( 'should accept a `string`' , ( ) => {
94
- new Assert ( ) . Date ( ) . validate ( '2014-10-16' ) ;
104
+ it ( 'should accept a string date' , ( ) => {
105
+ new Assert ( ) . Date ( ) . validate ( '2016-04-23' ) ;
106
+ } ) ;
107
+
108
+ it ( 'should accept an ISO-8601 string date' , ( ) => {
109
+ new Assert ( ) . Date ( ) . validate ( '2016-04-23T00:51:18.570Z' ) ;
110
+ } ) ;
111
+
112
+ it ( 'should accept a numeric timestamp' , ( ) => {
113
+ new Assert ( ) . Date ( ) . validate ( Date . now ( ) ) ;
95
114
} ) ;
96
115
} ) ;
0 commit comments