Home / File/ 500s.test.js — fastify Source File

500s.test.js — fastify Source File

Architecture documentation for 500s.test.js, a javascript file in the fastify codebase.

Entity Profile

Source Code

'use strict'

const { test } = require('node:test')
const Fastify = require('..')
const symbols = require('../lib/symbols.js')
const { FastifyError } = require('@fastify/error')

test('default 500', (t, done) => {
  t.plan(4)

  const fastify = Fastify()
  t.after(() => fastify.close())

  fastify.get('/', function (req, reply) {
    reply.send(new Error('kaboom'))
  })

  fastify.inject({
    method: 'GET',
    url: '/'
  }, (err, res) => {
    t.assert.ifError(err)
    t.assert.strictEqual(res.statusCode, 500)
    t.assert.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8')
    t.assert.deepStrictEqual(JSON.parse(res.payload), {
      error: 'Internal Server Error',
      message: 'kaboom',
      statusCode: 500
    })
    done()
  })
})

test('default 500 with non-error string', (t, done) => {
  t.plan(4)

  const fastify = Fastify()
  t.after(() => fastify.close())

  fastify.get('/', function (req, reply) {
    throw 'kaboom' // eslint-disable-line no-throw-literal
  })

  fastify.inject({
    method: 'GET',
    url: '/'
  }, (err, res) => {
    t.assert.ifError(err)
    t.assert.strictEqual(res.statusCode, 500)
    t.assert.strictEqual(res.headers['content-type'], 'text/plain; charset=utf-8')
    t.assert.deepStrictEqual(res.payload, 'kaboom')
    done()
  })
})

test('default 500 with non-error symbol', (t, done) => {
  t.plan(4)

  const fastify = Fastify()
  t.after(() => fastify.close())
// ... (363 more lines)

Frequently Asked Questions

What does 500s.test.js do?
500s.test.js is a source file in the fastify codebase, written in javascript.
Where is 500s.test.js in the architecture?
500s.test.js is located at test/500s.test.js (directory: test).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free