@navios/core 1.0.0 → 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +97 -11
- package/README.md +67 -220
- package/lib/async-context-6pdlnNLA.d.mts +237 -0
- package/lib/async-context-6pdlnNLA.d.mts.map +1 -0
- package/lib/async-context-Dqk7pE-D.d.cts +237 -0
- package/lib/async-context-Dqk7pE-D.d.cts.map +1 -0
- package/lib/attribute-factory-B3VuYnp7.d.cts +70 -0
- package/lib/attribute-factory-B3VuYnp7.d.cts.map +1 -0
- package/lib/attribute-factory-mKOXoVnV.d.mts +70 -0
- package/lib/attribute-factory-mKOXoVnV.d.mts.map +1 -0
- package/lib/attribute-value-CjX9ZkLq.cjs +172 -0
- package/lib/attribute-value-CjX9ZkLq.cjs.map +1 -0
- package/lib/attribute-value-DMEA255r.mjs +119 -0
- package/lib/attribute-value-DMEA255r.mjs.map +1 -0
- package/lib/basic-execution-context-CeGuhMOz.mjs +246 -0
- package/lib/basic-execution-context-CeGuhMOz.mjs.map +1 -0
- package/lib/basic-execution-context-DSk5MNtc.cjs +281 -0
- package/lib/basic-execution-context-DSk5MNtc.cjs.map +1 -0
- package/lib/execution-context-BPD3FeFb.d.mts +71 -0
- package/lib/execution-context-BPD3FeFb.d.mts.map +1 -0
- package/lib/execution-context-BTJdHhbf.d.cts +71 -0
- package/lib/execution-context-BTJdHhbf.d.cts.map +1 -0
- package/lib/execution-context-token-BXUKB2hf.cjs +112 -0
- package/lib/execution-context-token-BXUKB2hf.cjs.map +1 -0
- package/lib/execution-context-token-CrXmTvk2.mjs +77 -0
- package/lib/execution-context-token-CrXmTvk2.mjs.map +1 -0
- package/lib/index.cjs +1687 -4409
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +838 -3
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +838 -3
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +1573 -4219
- package/lib/index.mjs.map +1 -1
- package/lib/legacy-compat/index.cjs +72 -371
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +42 -382
- package/lib/legacy-compat/index.d.cts.map +1 -1
- package/lib/legacy-compat/index.d.mts +41 -382
- package/lib/legacy-compat/index.d.mts.map +1 -1
- package/lib/legacy-compat/index.mjs +51 -345
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/lib/module-Bha7GER_.mjs +135 -0
- package/lib/module-Bha7GER_.mjs.map +1 -0
- package/lib/module-DZewk_2r.cjs +164 -0
- package/lib/module-DZewk_2r.cjs.map +1 -0
- package/lib/module-graph-DCP9MHG0.cjs +147 -0
- package/lib/module-graph-DCP9MHG0.cjs.map +1 -0
- package/lib/module-graph-xvVEykFM.mjs +142 -0
- package/lib/module-graph-xvVEykFM.mjs.map +1 -0
- package/lib/module-metadata-C8S92seK.cjs +95 -0
- package/lib/module-metadata-C8S92seK.cjs.map +1 -0
- package/lib/module-metadata-k3RTt20x.mjs +66 -0
- package/lib/module-metadata-k3RTt20x.mjs.map +1 -0
- package/lib/module-options-Dmse0gii.d.mts +51 -0
- package/lib/module-options-Dmse0gii.d.mts.map +1 -0
- package/lib/module-options-IuDO-p8u.d.cts +51 -0
- package/lib/module-options-IuDO-p8u.d.cts.map +1 -0
- package/lib/testing/index.cjs +96 -414
- package/lib/testing/index.cjs.map +1 -1
- package/lib/testing/index.d.cts +25 -385
- package/lib/testing/index.d.cts.map +1 -1
- package/lib/testing/index.d.mts +24 -385
- package/lib/testing/index.d.mts.map +1 -1
- package/lib/testing/index.mjs +94 -408
- package/lib/testing/index.mjs.map +1 -1
- package/lib/transport.cjs +25 -0
- package/lib/transport.d.cts +190 -0
- package/lib/transport.d.cts.map +1 -0
- package/lib/transport.d.mts +190 -0
- package/lib/transport.d.mts.map +1 -0
- package/lib/transport.mjs +7 -0
- package/package.json +37 -17
- package/docs/README.md +0 -316
- package/docs/adapters.md +0 -308
- package/docs/application-setup.md +0 -524
- package/docs/attributes.md +0 -689
- package/docs/controllers.md +0 -373
- package/docs/endpoints.md +0 -444
- package/docs/exceptions.md +0 -352
- package/docs/guards.md +0 -550
- package/docs/legacy-compat.md +0 -356
- package/docs/modules.md +0 -377
- package/docs/quick-start.md +0 -290
- package/docs/services.md +0 -427
- package/docs/testing.md +0 -827
- package/lib/index-C0Sg16Eb.d.cts +0 -3365
- package/lib/index-C0Sg16Eb.d.cts.map +0 -1
- package/lib/index-DySQ6Dpd.d.mts +0 -3365
- package/lib/index-DySQ6Dpd.d.mts.map +0 -1
- package/lib/navios.factory-CO5MB_OK.cjs +0 -4125
- package/lib/navios.factory-CO5MB_OK.cjs.map +0 -1
- package/lib/navios.factory-D6Y94P9B.mjs +0 -3828
- package/lib/navios.factory-D6Y94P9B.mjs.map +0 -1
- package/lib/tokens-4J9sredA.mjs +0 -100
- package/lib/tokens-4J9sredA.mjs.map +0 -1
- package/lib/tokens-CWw9kyeD.cjs +0 -196
- package/lib/tokens-CWw9kyeD.cjs.map +0 -1
- package/lib/use-guards.decorator-BecoQSmE.mjs +0 -339
- package/lib/use-guards.decorator-BecoQSmE.mjs.map +0 -1
- package/lib/use-guards.decorator-C4ml9XaT.cjs +0 -447
- package/lib/use-guards.decorator-C4ml9XaT.cjs.map +0 -1
- package/project.json +0 -66
- package/src/__tests__/attribute.factory.spec.mts +0 -300
- package/src/__tests__/config.service.spec.mts +0 -43
- package/src/__tests__/console-logger.service.spec.mts +0 -312
- package/src/__tests__/controller-resolver.spec.mts +0 -229
- package/src/__tests__/controller.spec.mts +0 -58
- package/src/__tests__/guard-runner.service.spec.mts +0 -399
- package/src/__tests__/logger.service.spec.mts +0 -147
- package/src/__tests__/responders.spec.mts +0 -340
- package/src/__tests__/testing-module.spec.mts +0 -459
- package/src/__tests__/unit-testing-module.spec.mts +0 -424
- package/src/attribute.factory.mts +0 -325
- package/src/config/config-service.interface.mts +0 -47
- package/src/config/config.provider.mts +0 -69
- package/src/config/config.service.mts +0 -176
- package/src/config/index.mts +0 -5
- package/src/config/types.mts +0 -58
- package/src/config/utils/helpers.mts +0 -23
- package/src/config/utils/index.mts +0 -1
- package/src/decorators/controller.decorator.mts +0 -81
- package/src/decorators/endpoint.decorator.mts +0 -181
- package/src/decorators/header.decorator.mts +0 -38
- package/src/decorators/http-code.decorator.mts +0 -38
- package/src/decorators/index.mts +0 -8
- package/src/decorators/module.decorator.mts +0 -106
- package/src/decorators/multipart.decorator.mts +0 -169
- package/src/decorators/stream.decorator.mts +0 -155
- package/src/decorators/use-guards.decorator.mts +0 -73
- package/src/exceptions/bad-request.exception.mts +0 -28
- package/src/exceptions/conflict.exception.mts +0 -31
- package/src/exceptions/forbidden.exception.mts +0 -30
- package/src/exceptions/http.exception.mts +0 -33
- package/src/exceptions/index.mts +0 -7
- package/src/exceptions/internal-server-error.exception.mts +0 -33
- package/src/exceptions/not-found.exception.mts +0 -33
- package/src/exceptions/unauthorized.exception.mts +0 -30
- package/src/factories/adapter.factory.mts +0 -20
- package/src/factories/endpoint-adapter.factory.mts +0 -21
- package/src/factories/http-adapter.factory.mts +0 -20
- package/src/factories/index.mts +0 -8
- package/src/factories/multipart-adapter.factory.mts +0 -21
- package/src/factories/reply.factory.mts +0 -21
- package/src/factories/request.factory.mts +0 -21
- package/src/factories/stream-adapter.factory.mts +0 -20
- package/src/factories/xml-stream-adapter.factory.mts +0 -20
- package/src/index.mts +0 -16
- package/src/interfaces/abstract-adapter.interface.mts +0 -32
- package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
- package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
- package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
- package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
- package/src/interfaces/adapter-environment.interface.mts +0 -74
- package/src/interfaces/can-activate.mts +0 -38
- package/src/interfaces/http-header.mts +0 -18
- package/src/interfaces/index.mts +0 -11
- package/src/interfaces/navios-module.mts +0 -28
- package/src/interfaces/plugin.interface.mts +0 -139
- package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
- package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
- package/src/legacy-compat/attribute.factory.mts +0 -351
- package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
- package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
- package/src/legacy-compat/decorators/header.decorator.mts +0 -43
- package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
- package/src/legacy-compat/decorators/index.mts +0 -11
- package/src/legacy-compat/decorators/module.decorator.mts +0 -37
- package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
- package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
- package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
- package/src/legacy-compat/index.mts +0 -57
- package/src/logger/README.md +0 -3
- package/src/logger/console-logger.service.mts +0 -714
- package/src/logger/index.mts +0 -6
- package/src/logger/log-levels.mts +0 -21
- package/src/logger/logger-service.interface.mts +0 -42
- package/src/logger/logger.service.mts +0 -113
- package/src/logger/logger.tokens.mts +0 -44
- package/src/logger/utils/cli-colors.util.mts +0 -17
- package/src/logger/utils/filter-log-levelts.util.mts +0 -29
- package/src/logger/utils/index.mts +0 -5
- package/src/logger/utils/is-log-level-enabled.mts +0 -33
- package/src/logger/utils/is-log-level.util.mts +0 -10
- package/src/logger/utils/shared.utils.mts +0 -51
- package/src/metadata/controller.metadata.mts +0 -72
- package/src/metadata/handler.metadata.mts +0 -80
- package/src/metadata/index.mts +0 -4
- package/src/metadata/module.metadata.mts +0 -108
- package/src/metadata/navios-managed.metadata.mts +0 -42
- package/src/navios.application.mts +0 -484
- package/src/navios.environment.mts +0 -42
- package/src/navios.factory.mts +0 -158
- package/src/responders/enums/framework-error.enum.mts +0 -38
- package/src/responders/enums/index.mts +0 -1
- package/src/responders/index.mts +0 -4
- package/src/responders/interfaces/error-responder.interface.mts +0 -42
- package/src/responders/interfaces/error-response.interface.mts +0 -22
- package/src/responders/interfaces/index.mts +0 -3
- package/src/responders/interfaces/problem-details.interface.mts +0 -34
- package/src/responders/services/error-response-producer.service.mts +0 -143
- package/src/responders/services/forbidden-responder.service.mts +0 -77
- package/src/responders/services/index.mts +0 -5
- package/src/responders/services/internal-server-error-responder.service.mts +0 -57
- package/src/responders/services/not-found-responder.service.mts +0 -76
- package/src/responders/services/validation-error-responder.service.mts +0 -78
- package/src/responders/tokens/index.mts +0 -1
- package/src/responders/tokens/responder.tokens.mts +0 -84
- package/src/services/abstract-handler-adapter.service.mts +0 -366
- package/src/services/guard-runner.service.mts +0 -152
- package/src/services/index.mts +0 -4
- package/src/services/instance-resolver.service.mts +0 -177
- package/src/services/module-loader.service.mts +0 -252
- package/src/stores/index.mts +0 -1
- package/src/stores/request-id.store.mts +0 -85
- package/src/testing/index.mts +0 -3
- package/src/testing/testing-module.mts +0 -393
- package/src/testing/unit-testing-module.mts +0 -298
- package/src/tokens/adapter.token.mts +0 -6
- package/src/tokens/endpoint-adapter.token.mts +0 -8
- package/src/tokens/execution-context.token.mts +0 -9
- package/src/tokens/http-adapter.token.mts +0 -8
- package/src/tokens/index.mts +0 -10
- package/src/tokens/multipart-adapter.token.mts +0 -8
- package/src/tokens/navios-options.token.mts +0 -6
- package/src/tokens/reply.token.mts +0 -3
- package/src/tokens/request.token.mts +0 -3
- package/src/tokens/stream-adapter.token.mts +0 -8
- package/src/tokens/xml-stream-adapter.token.mts +0 -8
- package/src/utils/adapter-supports.util.mts +0 -47
- package/src/utils/index.mts +0 -1
- package/tsconfig.json +0 -21
- package/tsconfig.lib.json +0 -8
- package/tsconfig.spec.json +0 -15
- package/tsdown.config.mts +0 -35
- package/vitest.config.mts +0 -15
|
@@ -1,424 +0,0 @@
|
|
|
1
|
-
import { Injectable, InjectionToken } from '@navios/di'
|
|
2
|
-
import { afterEach, describe, expect, it } from 'vitest'
|
|
3
|
-
|
|
4
|
-
import { UnitTestingModule } from '../testing/unit-testing-module.mjs'
|
|
5
|
-
|
|
6
|
-
describe('UnitTestingModule', () => {
|
|
7
|
-
let unitTestingModule: UnitTestingModule | null = null
|
|
8
|
-
|
|
9
|
-
afterEach(async () => {
|
|
10
|
-
if (unitTestingModule) {
|
|
11
|
-
await unitTestingModule.close()
|
|
12
|
-
unitTestingModule = null
|
|
13
|
-
}
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
describe('create', () => {
|
|
17
|
-
it('should create a unit testing module with providers', async () => {
|
|
18
|
-
@Injectable()
|
|
19
|
-
class TestService {
|
|
20
|
-
getValue() {
|
|
21
|
-
return 'test'
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
unitTestingModule = UnitTestingModule.create({
|
|
26
|
-
providers: [{ token: TestService, useClass: TestService }],
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
expect(unitTestingModule).toBeInstanceOf(UnitTestingModule)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('should create with useValue provider', async () => {
|
|
33
|
-
const TOKEN = InjectionToken.create<string>('test-token')
|
|
34
|
-
|
|
35
|
-
unitTestingModule = UnitTestingModule.create({
|
|
36
|
-
providers: [{ token: TOKEN, useValue: 'test-value' }],
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
const value = await unitTestingModule.get(TOKEN)
|
|
40
|
-
expect(value).toBe('test-value')
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it('should create with useClass provider', async () => {
|
|
44
|
-
@Injectable()
|
|
45
|
-
class OriginalService {
|
|
46
|
-
getValue() {
|
|
47
|
-
return 'original'
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
@Injectable()
|
|
52
|
-
class MockService {
|
|
53
|
-
getValue() {
|
|
54
|
-
return 'mock'
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
unitTestingModule = UnitTestingModule.create({
|
|
59
|
-
providers: [{ token: OriginalService, useClass: MockService }],
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
const service = await unitTestingModule.get(OriginalService)
|
|
63
|
-
expect(service.getValue()).toBe('mock')
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
it('should create with useFactory provider', async () => {
|
|
67
|
-
const TOKEN = InjectionToken.create<{ value: string }>('factory-token')
|
|
68
|
-
|
|
69
|
-
unitTestingModule = UnitTestingModule.create({
|
|
70
|
-
providers: [
|
|
71
|
-
{
|
|
72
|
-
token: TOKEN,
|
|
73
|
-
useFactory: () => ({ value: 'from-factory' }),
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
const instance = await unitTestingModule.get(TOKEN)
|
|
79
|
-
expect(instance.value).toBe('from-factory')
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
describe('get', () => {
|
|
84
|
-
it('should resolve registered providers', async () => {
|
|
85
|
-
@Injectable()
|
|
86
|
-
class TestService {
|
|
87
|
-
getValue() {
|
|
88
|
-
return 'test'
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
unitTestingModule = UnitTestingModule.create({
|
|
93
|
-
providers: [{ token: TestService, useClass: TestService }],
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
const service = await unitTestingModule.get(TestService)
|
|
97
|
-
expect(service.getValue()).toBe('test')
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
it('should throw for unregistered providers in strict mode', async () => {
|
|
101
|
-
@Injectable()
|
|
102
|
-
class RegisteredService {}
|
|
103
|
-
|
|
104
|
-
@Injectable()
|
|
105
|
-
class UnregisteredService {}
|
|
106
|
-
|
|
107
|
-
unitTestingModule = UnitTestingModule.create({
|
|
108
|
-
providers: [{ token: RegisteredService, useClass: RegisteredService }],
|
|
109
|
-
allowUnregistered: false,
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
await expect(unitTestingModule.get(UnregisteredService)).rejects.toThrow()
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
it('should auto-mock unregistered providers when allowUnregistered is true', async () => {
|
|
116
|
-
@Injectable()
|
|
117
|
-
class RegisteredService {}
|
|
118
|
-
|
|
119
|
-
@Injectable()
|
|
120
|
-
class UnregisteredService {}
|
|
121
|
-
|
|
122
|
-
unitTestingModule = UnitTestingModule.create({
|
|
123
|
-
providers: [{ token: RegisteredService, useClass: RegisteredService }],
|
|
124
|
-
allowUnregistered: true,
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
const unregistered = await unitTestingModule.get(UnregisteredService)
|
|
128
|
-
|
|
129
|
-
// Auto-mocked service should exist but throw on method access
|
|
130
|
-
expect(unregistered).toBeDefined()
|
|
131
|
-
})
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
describe('auto-mocking', () => {
|
|
135
|
-
it('should enable auto-mocking with enableAutoMocking()', async () => {
|
|
136
|
-
@Injectable()
|
|
137
|
-
class UnregisteredService {}
|
|
138
|
-
|
|
139
|
-
unitTestingModule = UnitTestingModule.create({
|
|
140
|
-
providers: [],
|
|
141
|
-
allowUnregistered: false,
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
unitTestingModule.enableAutoMocking()
|
|
145
|
-
|
|
146
|
-
const service = await unitTestingModule.get(UnregisteredService)
|
|
147
|
-
expect(service).toBeDefined()
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
it('should disable auto-mocking with disableAutoMocking()', async () => {
|
|
151
|
-
@Injectable()
|
|
152
|
-
class UnregisteredService {}
|
|
153
|
-
|
|
154
|
-
unitTestingModule = UnitTestingModule.create({
|
|
155
|
-
providers: [],
|
|
156
|
-
allowUnregistered: true,
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
unitTestingModule.disableAutoMocking()
|
|
160
|
-
|
|
161
|
-
await expect(unitTestingModule.get(UnregisteredService)).rejects.toThrow()
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
it('should track auto-mocked services', async () => {
|
|
165
|
-
@Injectable()
|
|
166
|
-
class UnregisteredService {}
|
|
167
|
-
|
|
168
|
-
unitTestingModule = UnitTestingModule.create({
|
|
169
|
-
providers: [],
|
|
170
|
-
allowUnregistered: true,
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
await unitTestingModule.get(UnregisteredService)
|
|
174
|
-
|
|
175
|
-
expect(() => unitTestingModule!.expectAutoMocked(UnregisteredService)).not.toThrow()
|
|
176
|
-
})
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
describe('automatic method call tracking', () => {
|
|
180
|
-
it('should automatically track method calls via proxy', async () => {
|
|
181
|
-
@Injectable()
|
|
182
|
-
class TestService {
|
|
183
|
-
greet(name: string) {
|
|
184
|
-
return `Hello, ${name}!`
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
unitTestingModule = UnitTestingModule.create({
|
|
189
|
-
providers: [{ token: TestService, useClass: TestService }],
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
const service = await unitTestingModule.get(TestService)
|
|
193
|
-
service.greet('World')
|
|
194
|
-
|
|
195
|
-
expect(() => unitTestingModule!.expectCalled(TestService, 'greet')).not.toThrow()
|
|
196
|
-
expect(() =>
|
|
197
|
-
unitTestingModule!.expectCalledWith(TestService, 'greet', ['World']),
|
|
198
|
-
).not.toThrow()
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
it('should track multiple method calls', async () => {
|
|
202
|
-
@Injectable()
|
|
203
|
-
class TestService {
|
|
204
|
-
methodA() {
|
|
205
|
-
return 'a'
|
|
206
|
-
}
|
|
207
|
-
methodB(x: number, y: number) {
|
|
208
|
-
return x + y
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
unitTestingModule = UnitTestingModule.create({
|
|
213
|
-
providers: [{ token: TestService, useClass: TestService }],
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
const service = await unitTestingModule.get(TestService)
|
|
217
|
-
service.methodA()
|
|
218
|
-
service.methodB(1, 2)
|
|
219
|
-
service.methodB(3, 4)
|
|
220
|
-
|
|
221
|
-
expect(() => unitTestingModule!.expectCallCount(TestService, 'methodA', 1)).not.toThrow()
|
|
222
|
-
expect(() => unitTestingModule!.expectCallCount(TestService, 'methodB', 2)).not.toThrow()
|
|
223
|
-
})
|
|
224
|
-
|
|
225
|
-
it('should track async method calls', async () => {
|
|
226
|
-
@Injectable()
|
|
227
|
-
class AsyncService {
|
|
228
|
-
async fetchData(id: string) {
|
|
229
|
-
return { id, data: 'fetched' }
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
unitTestingModule = UnitTestingModule.create({
|
|
234
|
-
providers: [{ token: AsyncService, useClass: AsyncService }],
|
|
235
|
-
})
|
|
236
|
-
|
|
237
|
-
const service = await unitTestingModule.get(AsyncService)
|
|
238
|
-
await service.fetchData('123')
|
|
239
|
-
|
|
240
|
-
expect(() => unitTestingModule!.expectCalled(AsyncService, 'fetchData')).not.toThrow()
|
|
241
|
-
expect(() =>
|
|
242
|
-
unitTestingModule!.expectCalledWith(AsyncService, 'fetchData', ['123']),
|
|
243
|
-
).not.toThrow()
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
it('should expose getMethodCalls for custom assertions', async () => {
|
|
247
|
-
@Injectable()
|
|
248
|
-
class TestService {
|
|
249
|
-
process(value: string) {
|
|
250
|
-
return value.toUpperCase()
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
unitTestingModule = UnitTestingModule.create({
|
|
255
|
-
providers: [{ token: TestService, useClass: TestService }],
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
const service = await unitTestingModule.get(TestService)
|
|
259
|
-
service.process('hello')
|
|
260
|
-
service.process('world')
|
|
261
|
-
|
|
262
|
-
const calls = unitTestingModule.getMethodCalls(TestService)
|
|
263
|
-
|
|
264
|
-
expect(calls).toHaveLength(2)
|
|
265
|
-
expect(calls[0].args).toEqual(['hello'])
|
|
266
|
-
expect(calls[0].result).toBe('HELLO')
|
|
267
|
-
expect(calls[1].args).toEqual(['world'])
|
|
268
|
-
expect(calls[1].result).toBe('WORLD')
|
|
269
|
-
})
|
|
270
|
-
})
|
|
271
|
-
|
|
272
|
-
describe('assertion helpers', () => {
|
|
273
|
-
it('should expose expectResolved', async () => {
|
|
274
|
-
@Injectable()
|
|
275
|
-
class TestService {}
|
|
276
|
-
|
|
277
|
-
unitTestingModule = UnitTestingModule.create({
|
|
278
|
-
providers: [{ token: TestService, useClass: TestService }],
|
|
279
|
-
})
|
|
280
|
-
|
|
281
|
-
await unitTestingModule.get(TestService)
|
|
282
|
-
|
|
283
|
-
expect(() => unitTestingModule!.expectResolved(TestService)).not.toThrow()
|
|
284
|
-
})
|
|
285
|
-
|
|
286
|
-
it('should expose expectNotResolved', async () => {
|
|
287
|
-
@Injectable()
|
|
288
|
-
class TestService {}
|
|
289
|
-
|
|
290
|
-
unitTestingModule = UnitTestingModule.create({
|
|
291
|
-
providers: [{ token: TestService, useClass: TestService }],
|
|
292
|
-
})
|
|
293
|
-
|
|
294
|
-
expect(() => unitTestingModule!.expectNotResolved(TestService)).not.toThrow()
|
|
295
|
-
})
|
|
296
|
-
|
|
297
|
-
it('should expose expectNotCalled', async () => {
|
|
298
|
-
@Injectable()
|
|
299
|
-
class TestService {
|
|
300
|
-
method() {
|
|
301
|
-
return 'test'
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
unitTestingModule = UnitTestingModule.create({
|
|
306
|
-
providers: [{ token: TestService, useClass: TestService }],
|
|
307
|
-
})
|
|
308
|
-
|
|
309
|
-
await unitTestingModule.get(TestService)
|
|
310
|
-
// Method not called
|
|
311
|
-
|
|
312
|
-
expect(() => unitTestingModule!.expectNotCalled(TestService, 'method')).not.toThrow()
|
|
313
|
-
})
|
|
314
|
-
})
|
|
315
|
-
|
|
316
|
-
describe('service stats', () => {
|
|
317
|
-
it('should get service stats', async () => {
|
|
318
|
-
@Injectable()
|
|
319
|
-
class TestService {
|
|
320
|
-
doWork() {
|
|
321
|
-
return 'done'
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
unitTestingModule = UnitTestingModule.create({
|
|
326
|
-
providers: [{ token: TestService, useClass: TestService }],
|
|
327
|
-
})
|
|
328
|
-
|
|
329
|
-
const service = await unitTestingModule.get(TestService)
|
|
330
|
-
service.doWork()
|
|
331
|
-
service.doWork()
|
|
332
|
-
|
|
333
|
-
const stats = unitTestingModule.getServiceStats(TestService)
|
|
334
|
-
|
|
335
|
-
expect(stats.methodCalls).toHaveLength(2)
|
|
336
|
-
expect(stats.methodCalls[0].method).toBe('doWork')
|
|
337
|
-
})
|
|
338
|
-
})
|
|
339
|
-
|
|
340
|
-
describe('clearMethodCalls', () => {
|
|
341
|
-
it('should clear all method calls', async () => {
|
|
342
|
-
@Injectable()
|
|
343
|
-
class TestService {
|
|
344
|
-
method() {
|
|
345
|
-
return 'test'
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
unitTestingModule = UnitTestingModule.create({
|
|
350
|
-
providers: [{ token: TestService, useClass: TestService }],
|
|
351
|
-
})
|
|
352
|
-
|
|
353
|
-
const service = await unitTestingModule.get(TestService)
|
|
354
|
-
service.method()
|
|
355
|
-
service.method()
|
|
356
|
-
|
|
357
|
-
expect(unitTestingModule.getMethodCalls(TestService)).toHaveLength(2)
|
|
358
|
-
|
|
359
|
-
unitTestingModule.clearMethodCalls()
|
|
360
|
-
|
|
361
|
-
expect(unitTestingModule.getMethodCalls(TestService)).toHaveLength(0)
|
|
362
|
-
})
|
|
363
|
-
})
|
|
364
|
-
|
|
365
|
-
describe('registered and auto-mocked token tracking', () => {
|
|
366
|
-
it('should track registered token IDs', async () => {
|
|
367
|
-
@Injectable()
|
|
368
|
-
class ServiceA {}
|
|
369
|
-
|
|
370
|
-
@Injectable()
|
|
371
|
-
class ServiceB {}
|
|
372
|
-
|
|
373
|
-
unitTestingModule = UnitTestingModule.create({
|
|
374
|
-
providers: [
|
|
375
|
-
{ token: ServiceA, useClass: ServiceA },
|
|
376
|
-
{ token: ServiceB, useClass: ServiceB },
|
|
377
|
-
],
|
|
378
|
-
})
|
|
379
|
-
|
|
380
|
-
const registeredIds = unitTestingModule.getRegisteredTokenIds()
|
|
381
|
-
|
|
382
|
-
expect(registeredIds.size).toBe(2)
|
|
383
|
-
})
|
|
384
|
-
|
|
385
|
-
it('should track auto-mocked token IDs', async () => {
|
|
386
|
-
@Injectable()
|
|
387
|
-
class UnregisteredA {}
|
|
388
|
-
|
|
389
|
-
@Injectable()
|
|
390
|
-
class UnregisteredB {}
|
|
391
|
-
|
|
392
|
-
unitTestingModule = UnitTestingModule.create({
|
|
393
|
-
providers: [],
|
|
394
|
-
allowUnregistered: true,
|
|
395
|
-
})
|
|
396
|
-
|
|
397
|
-
await unitTestingModule.get(UnregisteredA)
|
|
398
|
-
await unitTestingModule.get(UnregisteredB)
|
|
399
|
-
|
|
400
|
-
const autoMockedIds = unitTestingModule.getAutoMockedTokenIds()
|
|
401
|
-
|
|
402
|
-
expect(autoMockedIds.size).toBe(2)
|
|
403
|
-
})
|
|
404
|
-
})
|
|
405
|
-
|
|
406
|
-
describe('close', () => {
|
|
407
|
-
it('should clean up resources', async () => {
|
|
408
|
-
@Injectable()
|
|
409
|
-
class TestService {}
|
|
410
|
-
|
|
411
|
-
unitTestingModule = UnitTestingModule.create({
|
|
412
|
-
providers: [{ token: TestService, useClass: TestService }],
|
|
413
|
-
})
|
|
414
|
-
|
|
415
|
-
await unitTestingModule.get(TestService)
|
|
416
|
-
await unitTestingModule.close()
|
|
417
|
-
|
|
418
|
-
// After close, method calls should be cleared
|
|
419
|
-
expect(unitTestingModule.getMethodCalls(TestService)).toHaveLength(0)
|
|
420
|
-
|
|
421
|
-
unitTestingModule = null // Prevent afterEach from calling close again
|
|
422
|
-
})
|
|
423
|
-
})
|
|
424
|
-
})
|