How can I migrate bad mocking practices? #698
-
|
Hello, I am trying to migrate a very large project from jest to rstest. We have thousands of files that do something like: class MockApiClient extends ApiClient {
fetch = rstest.fn().mockResolvedValue({ json: () => Promise.resolve({ data: [] }) })
}
export const mockApiClient = new MockApiClient({ baseDomain: 'https://example.com' });
import * as mockApiFile from '../../services';
mockApiFile.mockApiClient.fetch.mockResolvedValue()The problem is rspack finds that mockApiClient does NOT exist in the real services/index.js, which is correct, but it does exist in the mock: I understand this is a bad practice on our end, but, I can't migrate thousands of files that break this rule Any suggestions? I essentially need setup-files and it's global Thank you, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
In addition to compilation errors, can the test run as expected? Is the mock officially effective? |
Beta Was this translation helpful? Give feedback.
-
|
Thank you |
Beta Was this translation helpful? Give feedback.
In addition to compilation errors, can the test run as expected? Is the mock officially effective?
If it's just an
ESModulesLinkingErrorand doesn't affect actual execution, I think it's related to rstest(rspack) compiling the code beforehand. I can disable these errors in rstest.