Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 56 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |