Mocking service that implements OnReady during integration tests #1690
Answered
by
Romakita
detroitpro
asked this question in
Q&A
-
I have 1 service that I want to mock during integration testing. The service can take a long time to load and thus I don't want it loaded on each test run. beforeEach(async () => {
// bootstrap a new server, configure db to run in memory for tests.
const b = PlatformTest.bootstrap(Server, {
typeorm: [
{
name: 'default',
type: 'sqlite',
database: ':memory:',
dropSchema: true,
synchronize: true,
logging: false,
},
],
});
PlatformTest.inject([WorkerService], async (serviceToMock: WorkerService) => {
const someMock = jest.fn();
serviceToMock.$onReady = new someMock();
// await serviceToMock.$onReady();
});
await b();
});
afterEach(PlatformTest.reset);
it('should return runtime config', () => {
const config = PlatformTest.injector.get<PlatformConfiguration>(PlatformConfiguration);
console.debug(config); // testing throws here due to timeout.
}); This is what I've tried for mocking the service. |
Beta Was this translation helpful? Give feedback.
Answered by
Romakita
Dec 24, 2021
Replies: 1 comment
-
try this :) @OverrideProvider(WorkerService)
class MyWorkerService extends WorkerService {
$onReady() {
console.log('mocked')
}
}
beforeEach(() => PlatformTest.bootstrap(Server, {
typeorm: [
{
name: 'default',
type: 'sqlite',
database: ':memory:',
dropSchema: true,
synchronize: true,
logging: false,
},
],
}));
afterEach(PlatformTest.reset);
it('should return runtime config', () => {
const config = PlatformTest.injector.get<PlatformConfiguration>(PlatformConfiguration);
console.debug(config); // testing throws here due to timeout.
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
detroitpro
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try this :)