app.test.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // For more information about this file see https://dove.feathersjs.com/guides/cli/app.test.html
  2. import assert from 'assert'
  3. import axios from 'axios'
  4. import type { Server } from 'http'
  5. import { app } from '../src/app'
  6. const port = app.get('port')
  7. const appUrl = `http://${app.get('host')}:${port}`
  8. describe('Feathers application tests', () => {
  9. let server: Server
  10. before(async () => {
  11. server = await app.listen(port)
  12. })
  13. after(async () => {
  14. await app.teardown()
  15. })
  16. it('starts and shows the index page', async () => {
  17. const { data } = await axios.get<string>(appUrl)
  18. assert.ok(data.indexOf('<html lang="en">') !== -1)
  19. })
  20. it('shows a 404 JSON error', async () => {
  21. try {
  22. await axios.get(`${appUrl}/path/to/nowhere`, {
  23. responseType: 'json'
  24. })
  25. assert.fail('should never get here')
  26. } catch (error: any) {
  27. const { response } = error
  28. assert.strictEqual(response?.status, 404)
  29. assert.strictEqual(response?.data?.code, 404)
  30. assert.strictEqual(response?.data?.name, 'NotFound')
  31. }
  32. })
  33. })