Passed
Pull Request — main (#22)
by Lorenzo
01:22
created

src/core/decorators/Bean.spec.ts   A

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 56
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 42
mnd 0
bc 0
fnc 1
dl 0
loc 56
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A Class.getId 0 3 1
1
import { flushPromises } from '@test/utils/testUtils';
2
import { Bean } from '@/main';
3
import { registeredBeans, registeredMethods } from '@/core';
4
5
jest.mock('@/core', () => ({
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('Bean.ts', () => {
16
  beforeEach(() => {
17
    jest.resetAllMocks();
18
    registeredBeans.clear();
19
    registeredMethods.clear();
20
  });
21
22
  it('registers a bean', async () => {
23
    // WHEN
24
    @Bean
25
    class Class {
26
      id = 42;
27
    }
28
    const C: any = Class;
29
    await flushPromises();
30
    await flushPromises();
31
32
    // THEN
33
    expect(registeredBeans.get('Class')).toBe(C.instance);
34
    expect(C.instance.id).toStrictEqual(42);
35
  });
36
37
  it('registers a bean and its methods', async () => {
38
    // WHEN
39
    @Bean
40
    class Class {
41
      id: number = 1001;
42
43
      getId() {
44
        return 42;
45
      }
46
    }
47
    const C: any = Class;
48
    await flushPromises();
49
    await flushPromises();
50
51
    // THEN
52
    expect(registeredBeans.get('Class')).toBe(C.instance);
53
    expect(registeredMethods.get(C.instance.getId)).toBe(C.instance);
54
  });
55
});
56