@@ -20,8 +20,8 @@ const Assert = BaseAssert.extend({
2020 */
2121
2222describe ( '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 = [ [ ] , { } ] ;
2525
2626 choices . forEach ( choice => {
2727 try {
@@ -30,7 +30,7 @@ describe('DateAssert', () => {
3030 should . fail ( ) ;
3131 } catch ( e ) {
3232 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 ' ) ;
3434 }
3535 } ) ;
3636 } ) ;
@@ -61,6 +61,17 @@ describe('DateAssert', () => {
6161 }
6262 } ) ;
6363
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+
6475 it ( 'should throw an error if value does not pass strict validation' , ( ) => {
6576 try {
6677 new Assert ( ) . Date ( { format : 'YYYY-MM-DD' } ) . validate ( '2000.12.30' ) ;
@@ -82,15 +93,23 @@ describe('DateAssert', () => {
8293 }
8394 } ) ;
8495
85- it ( 'should accept a `Date`' , ( ) => {
96+ it ( 'should accept an instance of `Date`' , ( ) => {
8697 new Assert ( ) . Date ( ) . validate ( new Date ( ) ) ;
8798 } ) ;
8899
89100 it ( 'should accept a correctly formatted date' , ( ) => {
90101 new Assert ( ) . Date ( { format : 'YYYY-MM-DD' } ) . validate ( '2000-12-30' ) ;
91102 } ) ;
92103
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 ( ) ) ;
95114 } ) ;
96115} ) ;
0 commit comments