@@ -8,6 +8,22 @@ import {
8
8
} from "core/plugins/json-schema-5-samples/fn/index"
9
9
10
10
describe ( "sampleFromSchema" , ( ) => {
11
+ const oriDate = Date
12
+
13
+ beforeEach ( ( ) => {
14
+ // eslint-disable-next-line no-global-assign
15
+ Date = function ( ) {
16
+ this . toISOString = function ( ) {
17
+ return "2025-04-18T09:13:28.927Z"
18
+ }
19
+ }
20
+ } )
21
+
22
+ afterEach ( ( ) => {
23
+ // eslint-disable-next-line no-global-assign
24
+ Date = oriDate
25
+ } )
26
+
11
27
it ( "handles Immutable.js objects for nested schemas" , function ( ) {
12
28
let definition = fromJS ( {
13
29
"type" : "object" ,
@@ -341,12 +357,9 @@ describe("sampleFromSchema", () => {
341
357
format : "date-time"
342
358
}
343
359
344
- // 0-20 chops off milliseconds
345
- // necessary because test latency can cause failures
346
- // it would be better to mock Date globally and expect a string - KS 11/18
347
- let expected = new Date ( ) . toISOString ( ) . substring ( 0 , 20 )
360
+ let expected = "2025-04-18T09:13:28.927Z"
348
361
349
- expect ( sampleFromSchema ( definition ) ) . toContain ( expected )
362
+ expect ( sampleFromSchema ( definition ) ) . toEqual ( expected )
350
363
} )
351
364
352
365
it ( "returns example value for date property" , ( ) => {
@@ -355,7 +368,18 @@ describe("sampleFromSchema", () => {
355
368
format : "date"
356
369
}
357
370
358
- let expected = new Date ( ) . toISOString ( ) . substring ( 0 , 10 )
371
+ let expected = "2025-04-18"
372
+
373
+ expect ( sampleFromSchema ( definition ) ) . toEqual ( expected )
374
+ } )
375
+
376
+ it ( "returns example value for time property" , ( ) => {
377
+ let definition = {
378
+ type : "string" ,
379
+ format : "time"
380
+ }
381
+
382
+ let expected = "09:13:28.927"
359
383
360
384
expect ( sampleFromSchema ( definition ) ) . toEqual ( expected )
361
385
} )
0 commit comments