1
0
mirror of synced 2025-12-19 18:10:59 -05:00
Files
docs/src/events/tests/middleware-errors.js
2024-04-16 17:07:22 +00:00

26 lines
827 B
JavaScript

import { describe, expect, test } from 'vitest'
import { validateJson } from '#src/tests/lib/validate-json-schema.js'
import { formatErrors } from '../lib/middleware-errors.js'
import { schemas } from '../lib/schema.js'
describe('formatErrors', () => {
test('should produce objects that match the validation spec', () => {
expect.extend({
toMatchSchema(data, schema) {
const { isValid, errors } = validateJson(schema, data)
return {
pass: isValid,
message: () => (isValid ? '' : errors.message),
}
},
})
// Produce an error
const { errors } = validateJson({ type: 'string' }, 0)
const formattedErrors = formatErrors(errors, '')
for (const formatted of formattedErrors) {
expect(formatted).toMatchSchema(schemas.validation)
}
})
})