Test Failed
Branch feature/typescript5 (203f49)
by Lorenzo
03:01
created

TestRouter.test   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
import { flushPromises } from '@test/utils/testUtils';
2
import * as http from 'http';
3
import { Request, Response } from 'express';
4
import supertest from 'supertest';
5
import ExpressBeans from '@/ExpressBeans';
6
import { Route, RouterBean } from '@/main';
7
8
describe('ExpressBeans.ts', () => {
9
  let server: http.Server;
10
  let application: ExpressBeans;
11
  beforeEach(async () => {
12
    vi.resetModules();
13
    application = new ExpressBeans({ listen: false });
14
    server = application.getApp().listen(8080);
15
    await flushPromises();
16
  });
17
18
  afterEach(() => {
19
    server.close();
20
  });
21
22
  test('start of application', async () => {
23
    // GIVEN
24
    @RouterBean('/test')
25
    class TestRouter {
26
      @Route('GET', '/42')
27
      test(_req: Request, res: Response) {
28
        res.send('42 is the answer');
29
      }
30
    }
31
    application = new ExpressBeans({ listen: false, routerBeans: [TestRouter] });
32
    server = application.getApp().listen(8080);
33
34
    // WHEN
35
    const { body } = supertest(server).get('/test/42');
36
37
    // THEN
38
    expect(body).toBe(true);
39
  });
40
41
  test('creation of a new application', async () => {
42
    // WHEN
43
    await flushPromises();
44
45
    // THEN
46
    expect(application instanceof ExpressBeans).toBe(true);
47
  });
48
});
49