8000 CR · MoLow/fast-json-stringify@35f3539 · GitHub
[go: up one dir, main page]

Skip to content

Commit 35f3539

Browse files
committed
CR
1 parent 04d0b3c commit 35f3539

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

test/any.test.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ test('empty schema on anyOf', (t) => {
154154
})
155155

156156
test('should throw a TypeError with the path to the key of the invalid value /1', (t) => {
157-
t.plan(1)
157+
t.plan(3)
158158

159159
// any on Foo codepath.
160160
const schema = {
@@ -186,16 +186,21 @@ test('should throw a TypeError with the path to the key of the invalid value /1'
186186

187187
const stringify = build(schema)
188188

189-
t.throws(() => stringify({ kind: 'Baz', value: 1 }), Object.assign(new TypeError('The value of \'#\' does not match schema definition.'), {
190-
validationErrors: [
191-
{ message: 'must be equal to one of the allowed values', schemaPath: '#/properties/kind/enum', instancePath: '/kind' },
192-
{ message: 'must be equal to one of the allowed values', schemaPath: '#/properties/kind/enum', instancePath: '/kind' }
193-
]
194-
}))
189+
try {
190+
stringify({ kind: 'Baz', value: 1 })
191+
t.fail('should throw')
192+
} catch (err) {
193+
t.equal(err.message, 'The value of \'#\' does not match schema definition.')
194+
t.same(err.validationErrors, [
195+
{ message: 'must be equal to one of the allowed values', schemaPath: '#/properties/kind/enum', instancePath: '/kind', keyword: 'enum', params: { allowedValues: ['Foo'] } },
196+
{ message: 'must be equal to one of the allowed values', schemaPath: '#/properties/kind/enum', instancePath: '/kind', keyword: 'enum', params: { allowedValues: ['Bar'] } }
197+
])
198+
t.ok(err instanceof TypeError)
199+
}
195200
})
196201

197202
test('should throw a TypeError with the path to the key of the invalid value /2', (t) => {
198-
t.plan(1)
203+
t.plan(3)
199204

200205
// any on Foo codepath.
201206
const schema = {
@@ -232,10 +237,15 @@ test('should throw a TypeError with the path to the key of the invalid value /2'
232237

233238
const stringify = build(schema)
234239

235-
t.throws(() => stringify({ data: { kind: 'Baz', value: 1 } }), Object.assign(new TypeError('The value of \'#/properties/data\' does not match schema definition.'), {
236-
validationErrors: [
237-
{ message: 'must be equal to one of the allowed values', schemaPath: '#/properties/kind/enum', instancePath: '/kind' },
238-
{ message: 'must be equal to one of the allowed values', schemaPath: '#/properties/kind/enum', instancePath: '/kind' }
239-
]
240-
}))
240+
try {
241+
stringify({ data: { kind: 'Baz', value: 1 } })
242+
t.fail('should throw')
243+
} catch (err) {
244+
t.equal(err.message, 'The value of \'#/properties/data\' does not match schema definition.')
245+
t.same(err.validationErrors, [
246+
{ message: 'must be equal to one of the allowed values', schemaPath: '#/properties/kind/enum', instancePath: '/kind', keyword: 'enum', params: { allowedValues: ['Foo'] } },
247+
{ message: 'must be equal to one of the allowed values', schemaPath: '#/properties/kind/enum', instancePath: '/kind', keyword: 'enum', params: { allowedValues: ['Bar'] } }
248+
])
249+
t.ok(err instanceof TypeError)
250+
}
241251
})

0 commit comments

Comments
 (0)
0