#useMocker not being called
5 messages · Page 1 of 1 (latest)
Please do not screenshot code as it causes a number of issues: ⚠️
- Ease of assistance: if someone wants to copy your code and correct it, they cannot. Making it easy for people to help you is in your best interests.
- Editorializing: it's common to try to make images small, which means you're likely to crop out code relevant to your issue
- Accessibility: wide images can be hard to read on mobile devices, and are impossible for screen readers.
- Legibility: you cannot read screenshots of code directly, instead you have to open them in an enlarged context.
- Bandwidth usage/clutter: some of our members use metered connections, and it is wasteful for them to download images of a text.
For a small amount of code, please use Markdown code blocks.
The issue lies in how you're using useMocker. In nest, useMocker is designed to work with Test.createTestingModule to intercept and provide mock implementations for specific providers
@thick totem you are saying that I should change to only import the controller and then the useMocker should work? because I've tried that and also didn't work, so I'm not sure what to do.. I basically want to mock some controller's methods, and looks like this is the only way is using the useMocker but I just can't get it to work, and it's so weird that is not even being called
const moduleRef = await Test.createTestingModule({
imports: [AppModule],
useMocker: (token) => {
console.log('Mocking token:', token);
switch (token) {
case SubscriptionController:
const mock = new SubscriptionControllerMock();
mock.createCustomerPortalSession.mockImplementation(() => {});
mock.createConfiguration.mockImplementation(() => {});
mock.getConfigurations.mockImplementation(() => {});
mock.subscribe.mockImplementation(() => {});
mock.getConfiguration.mockImplementation(() => {});
return mock;
default:
throw new Error('e');
}
}
}).compile();```