@@ -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 timestamp ' , ( ) => {
24+ const choices = [ [ ] , { } ] ;
2525
2626 choices . forEach ( choice => {
2727 try {
@@ -30,11 +30,21 @@ 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 } ) ;
3737
38+ it ( 'should throw an error if the input value is an invalid timestamp' , ( ) => {
39+ try {
40+ new Assert ( ) . Date ( ) . validate ( - Number . MAX_VALUE ) ;
41+
42+ should . fail ( ) ;
43+ } catch ( e ) {
44+ e . should . be . instanceOf ( Violation ) ;
45+ }
46+ } ) ;
47+
3848 it ( 'should expose `assert` equal to `Date`' , ( ) => {
3949 try {
4050 new Assert ( ) . Date ( ) . validate ( 'foo' ) ;
@@ -45,11 +55,19 @@ describe('DateAssert', () => {
4555 }
4656 } ) ;
4757
48- it ( 'should accept a `Date`' , ( ) => {
58+ it ( 'should accept an instance of `Date`' , ( ) => {
4959 new Assert ( ) . Date ( ) . validate ( new Date ( ) ) ;
5060 } ) ;
5161
52- it ( 'should accept a `string`' , ( ) => {
53- new Assert ( ) . Date ( ) . validate ( '2014-10-16' ) ;
62+ it ( 'should accept a string date' , ( ) => {
63+ new Assert ( ) . Date ( ) . validate ( '2016-04-23' ) ;
64+ } ) ;
65+
66+ it ( 'should accept an ISO-8601 string date' , ( ) => {
67+ new Assert ( ) . Date ( ) . validate ( '2016-04-23T00:51:18.570Z' ) ;
68+ } ) ;
69+
70+ it ( 'should accept a numeric timestamp' , ( ) => {
71+ new Assert ( ) . Date ( ) . validate ( Date . now ( ) ) ;
5472 } ) ;
5573} ) ;
0 commit comments