UNPKG

951 BJavaScriptView Raw
1'use strict'
2
3const t = require('tap')
4const test = t.test
5const Fastify = require('..')
6
7test('nullable string', t => {
8 t.plan(3)
9 const fastify = Fastify()
10 fastify.route({
11 method: 'POST',
12 url: '/',
13 handler: (req, reply) => {
14 t.same(req.body.hello, null)
15 reply.code(200).send(req.body)
16 },
17 schema: {
18 body: {
19 type: 'object',
20 properties: {
21 hello: {
22 type: 'string',
23 format: 'email',
24 nullable: true
25 }
26 }
27 },
28 response: {
29 200: {
30 type: 'object',
31 properties: {
32 hello: {
33 type: 'string',
34 format: 'email',
35 nullable: true
36 }
37 }
38 }
39 }
40 }
41 })
42 fastify.inject({
43 method: 'POST',
44 url: '/',
45 body: {
46 hello: null
47 }
48 }, (err, res) => {
49 t.error(err)
50 t.same(res.payload.hello, null)
51 })
52})