admin管理员组文章数量:1316329
I need to mock some functions in my controller, and reading the docks, looks like I should use the useMocker
function to do that, the problem is that useMocker
is never called.
This is my current setup:
reEach(async () => {
const moduleRef = await Test.createTestingModule({
imports: [NestjsFormDataModule, ConfigModule],
controllers: [SubscriptionController],
})
.useMocker((token) => {
console.log('TOKEN = ', token);
if (token === SubscriptionController) {
const mock = new SubscriptionControllerMock();
mock.createCustomerPortalSession.mockImplementation(() => {});
mock.createConfiguration.mockImplementation(() => {});
mock.getConfigurations.mockImplementation(() => {});
mock.subscribe.mockImplementation(() => {});
mock.getConfiguration.mockImplementation(() => {});
return mock;
}
})
pile();
app = moduleRef.createNestApplication();
({ agent } = await setupTestAuth(app, { admin: true }));
});
And the SubscriptionControllerMock
class is just a class that extends the SubscriptionController
but overrides the functions that I want to mock with jest.fn()
, like this:
export class SubscriptionControllerMock extends SubscriptionController {
createConfiguration = jest.fn();
getConfiguration = jest.fn();
getConfigurations = jest.fn();
updateConfiguration = jest.fn();
subscribe = jest.fn();
deleteConfiguration = jest.fn();
createCheckoutSession = jest.fn();
createCustomerPortalSession = jest.fn();
webhooks = jest.fn();
}
For some reason the useMocker
is never called and I even tried using overrideProvider
with the controller but also doesn't work and I can't find anywhere an example of someone that have done this. Please, help!
本文标签: testingHow to mock some controller functionsStack Overflow
版权声明:本文标题:testing - How to mock some controller functions? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742004144a2411617.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论