@@ -40,6 +40,25 @@ test('render a date in a string when format is date-format as ISOString', (t) =>
40
40
t . ok ( validate ( JSON . parse ( output ) ) , 'valid schema' )
41
41
} )
42
42
43
+ test ( 'render a nullable date in a string when format is date-format as ISOString' , ( t ) => {
44
+ t . plan ( 2 )
45
+
46
+ const schema = {
47
+ title : 'a date in a string' ,
48
+ type : 'string' ,
49
+ format : 'date-time' ,
50
+ nullable : true
51
+ }
52
+ const toStringify = new Date ( )
53
+
54
+ const validate = validator ( schema )
55
+ const stringify = build ( schema )
56
+ const output = stringify ( toStringify )
57
+
58
+ t . equal ( output , JSON . stringify ( toStringify ) )
59
+ t . ok ( validate ( JSON . parse ( output ) ) , 'valid schema' )
60
+ } )
61
+
43
62
test ( 'render a date in a string when format is date as YYYY-MM-DD' , ( t ) => {
44
63
t . plan ( 2 )
45
64
@@ -58,6 +77,25 @@ test('render a date in a string when format is date as YYYY-MM-DD', (t) => {
58
77
t . ok ( validate ( JSON . parse ( output ) ) , 'valid schema' )
59
78
} )
60
79
80
+ test ( 'render a nullable date in a string when format is date as YYYY-MM-DD' , ( t ) => {
81
+ t . plan ( 2 )
82
+
83
+ const schema = {
84
+ title : 'a date in a string' ,
85
+ type : 'string' ,
86
+ format : 'date' ,
87
+ nullable : true
88
+ }
89
+ const toStringify = new Date ( )
90
+
91
+ const validate = validator ( schema )
92
+ const stringify = build ( schema )
93
+ const output = stringify ( toStringify )
94
+
95
+ t . equal ( output , `"${ moment ( toStringify ) . format ( 'YYYY-MM-DD' ) } "` )
96
+ t . ok ( validate ( JSON . parse ( output ) ) , 'valid schema' )
97
+ } )
98
+
61
99
test ( 'verify padding for rendered date in a string when format is date' , ( t ) => {
62
100
t . plan ( 2 )
63
101
@@ -97,6 +135,28 @@ test('render a date in a string when format is time as kk:mm:ss', (t) => {
97
135
t . ok ( validate ( JSON . parse ( output ) ) , 'valid schema' )
98
136
} )
99
137
138
+ test ( 'render a nullable date in a string when format is time as kk:mm:ss' , ( t ) => {
139
+ t . plan ( 3 )
140
+
141
+ const schema = {
142
+ title : 'a date in a string' ,
143
+ type : 'string' ,
144
+ format : 'time' ,
145
+ nullable : true
146
+ }
147
+ const toStringify = new Date ( )
148
+
149
+ const validate = validator ( schema )
150
+ const stringify = build ( schema )
151
+ const output = stringify ( toStringify )
152
+
153
+ validate ( JSON . parse ( output ) )
154
+ t . equal ( validate . errors , null )
155
+
156
+ t . equal ( output , `"${ moment ( toStringify ) . format ( 'HH:mm:ss' ) } "` )
157
+ t . ok ( validate ( JSON . parse ( output ) ) , 'valid schema' )
158
+ } )
159
+
100
160
test ( 'render a midnight time' , ( t ) => {
101
161
t . plan ( 3 )
102
162
0 commit comments