fast-json-stringify 3.2.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -232,7 +232,7 @@ test('required numbers', (t) => {
232
232
  })
233
233
  t.fail()
234
234
  } catch (e) {
235
- t.equal(e.message, '"num" is required!')
235
+ t.equal(e.message, 'The value "aaa" cannot be converted to an integer.')
236
236
  t.pass()
237
237
  }
238
238
  })
@@ -3,15 +3,13 @@
3
3
  const t = require('tap')
4
4
  const build = require('..')
5
5
 
6
- const stringify = build({
7
- $defs: {
8
- type: 'foooo"bar'
9
- },
10
- patternProperties: {
11
- x: { $ref: '#/$defs' }
12
- }
13
- })
14
-
15
6
  t.throws(() => {
16
- stringify({ x: 0 })
17
- }, 'Cannot coerce 0 to "foo"bar"')
7
+ build({
8
+ $defs: {
9
+ type: 'foooo"bar'
10
+ },
11
+ patternProperties: {
12
+ x: { $ref: '#/$defs' }
13
+ }
14
+ })
15
+ }, 'foooo"bar unsupported')
@@ -1,7 +1,6 @@
1
1
  'use strict'
2
2
 
3
3
  const test = require('tap').test
4
- const moment = require('moment')
5
4
  const build = require('..')
6
5
 
7
6
  test('possibly nullable integer primitive alternative', (t) => {
@@ -88,6 +87,27 @@ test('possibly nullable number primitive alternative with null value', (t) => {
88
87
  t.equal(value, '{"data":0}')
89
88
  })
90
89
 
90
+ test('possibly nullable number primitive alternative with null value', (t) => {
91
+ t.plan(1)
92
+
93
+ const schema = {
94
+ title: 'simple object with multi-type nullable primitive',
95
+ type: 'object',
96
+ properties: {
97
+ data: {
98
+ type: ['boolean']
99
+ }
100
+ }
101
+ }
102
+
103
+ const stringify = build(schema)
104
+
105
+ const value = stringify({
106
+ data: null
107
+ })
108
+ t.equal(value, '{"data":false}')
109
+ })
110
+
91
111
  test('nullable integer primitive', (t) => {
92
112
  t.plan(1)
93
113
 
@@ -361,7 +381,7 @@ test('string type array can handle dates', (t) => {
361
381
  const stringify = build(schema)
362
382
  const value = stringify({
363
383
  date: new Date('2018-04-20T07:52:31.017Z'),
364
- dateObject: moment('2018-04-21T07:52:31.017Z')
384
+ dateObject: new Date('2018-04-21T07:52:31.017Z')
365
385
  })
366
386
  t.equal(value, '{"date":"2018-04-20T07:52:31.017Z","dateObject":"2018-04-21T07:52:31.017Z"}')
367
387
  })
@@ -433,5 +453,22 @@ test('should throw an error when type is array and object is null', (t) => {
433
453
  }
434
454
 
435
455
  const stringify = build(schema)
436
- t.throws(() => stringify({ arr: null }), new TypeError('Property \'arr\' should be of type array, received \'null\' instead.'))
456
+ t.throws(() => stringify({ arr: null }), new TypeError('The value \'null\' does not match schema definition.'))
457
+ })
458
+
459
+ test('throw an error if none of types matches', (t) => {
460
+ t.plan(1)
461
+
462
+ const schema = {
463
+ title: 'simple object with multi-type nullable primitive',
464
+ type: 'object',
465
+ properties: {
466
+ data: {
467
+ type: ['number', 'boolean']
468
+ }
469
+ }
470
+ }
471
+
472
+ const stringify = build(schema)
473
+ t.throws(() => stringify({ data: 'string' }), 'The value "string" does not match schema definition.')
437
474
  })