remove inline providers from unit tests
This commit is contained in:
parent
92892338f3
commit
a3e969625d
6 changed files with 33 additions and 76 deletions
|
|
@ -18,6 +18,7 @@ import { RelayService } from '@/core/RelayService.js';
|
|||
import { SystemAccountService } from '@/core/SystemAccountService.js';
|
||||
import { GlobalModule } from '@/GlobalModule.js';
|
||||
import { UtilityService } from '@/core/UtilityService.js';
|
||||
import { CoreModule } from '@/core/CoreModule.js';
|
||||
|
||||
const moduleMocker = new ModuleMocker(global);
|
||||
|
||||
|
|
@ -30,26 +31,17 @@ describe('RelayService', () => {
|
|||
app = await Test.createTestingModule({
|
||||
imports: [
|
||||
GlobalModule,
|
||||
],
|
||||
providers: [
|
||||
IdService,
|
||||
ApRendererService,
|
||||
RelayService,
|
||||
UserEntityService,
|
||||
SystemAccountService,
|
||||
UtilityService,
|
||||
CoreModule,
|
||||
],
|
||||
})
|
||||
.useMocker((token) => {
|
||||
if (token === QueueService) {
|
||||
return { deliver: jest.fn() };
|
||||
}
|
||||
if (typeof token === 'function') {
|
||||
const mockMetadata = moduleMocker.getMetadata(token) as MockFunctionMetadata<any, any>;
|
||||
const Mock = moduleMocker.generateFromMetadata(mockMetadata);
|
||||
return new Mock();
|
||||
}
|
||||
})
|
||||
.overrideProvider(QueueService).useValue({ deliver: jest.fn() })
|
||||
.compile();
|
||||
|
||||
await app.init();
|
||||
|
|
@ -63,6 +55,10 @@ describe('RelayService', () => {
|
|||
await app.close();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
queueService.deliver.mockReset();
|
||||
});
|
||||
|
||||
test('addRelay', async () => {
|
||||
const result = await relayService.addRelay('https://example.com');
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue