Passed
Push — main ( b29f4f...6a3653 )
by Lorenzo
01:09 queued 13s
created

Class   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 7
dl 0
loc 7
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A init 0 5 1
1
import { flushPromises } from '@test/utils/testUtils';
2
import { registeredBeans, registeredMethods } from '@/decorators';
3
import { Setup } from '@/decorators/Setup';
4
5
jest.mock('@/decorators', () => ({
6
  registeredBeans: new Map(),
7
  registeredMethods: new Map(),
8
  logger: {
9
    info: jest.fn(),
10
    debug: jest.fn(),
11
    error: jest.fn(),
12
  },
13
}));
14
15
describe('Setup.ts', () => {
16
  beforeEach(() => {
17
    jest.resetAllMocks();
18
    registeredMethods.clear();
19
    registeredBeans.clear();
20
  });
21
22
  it('execute a setup function', async () => {
23
    // GIVEN
24
    const mock = jest.fn();
25
    class Class {
26
      initialized: boolean = false;
27
28
      @Setup
29
      init() {
30
        this.initialized = true;
31
        mock();
32
      }
33
    }
34
    const bean: any = new Class();
35
    registeredMethods.set(bean.init, bean);
36
    registeredBeans.set('Class', bean);
37
    await flushPromises();
38
39
    // THEN
40
    expect(bean.initialized)
41
      .toBe(true);
42
    expect(mock).toHaveBeenCalled();
43
  });
44
45
  it('execute a setup async function', async () => {
46
    // GIVEN
47
    const mock = jest.fn();
48
    class Class {
49
      initialized: boolean = false;
50
51
      @Setup
52
      async init() {
53
        this.initialized = true;
54
        mock();
55
      }
56
    }
57
    const bean: any = new Class();
58
    registeredMethods.set(bean.init, bean);
59
    registeredBeans.set('Class', bean);
60
    await flushPromises();
61
62
    // THEN
63
    expect(bean.initialized)
64
      .toBe(true);
65
    expect(mock).toHaveBeenCalled();
66
  });
67
});
68