This repository was archived by the owner on Jan 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Mocking doesn't work with aliases set in jsc.paths #174
Copy link
Copy link
Open
Description
I can get jsc.paths working just fine and resolving things, for example this jest config and test:
export const config = {
transform: {
'\\.(ts|tsx)$': [
'@swc/jest',
{
jsc: {
baseUrl: '.',
paths: {
'@monorepo/some-library': ['libs/some-library/src/index.ts'],
},
},
},
],
},
};
export default config;
import { CONSTANT } from '@monorepo/some-library';
describe('adding', () => {
it('works', () => {
console.log({ CONSTANT });
expect(1 + 1).toBe(2);
});
});
^ the constant logs in the console just fine
but as soon as I try to mock the local library, I get an error. Here's an updated test:
import { CONSTANT } from '@monorepo/some-library';
jest.mock('@monorepo/some-library', () => ({ CONSTANT: 'stubbed constant' }));
describe('adding', () => {
it('works', () => {
console.log({ CONSTANT });
expect(1 + 1).toBe(2);
});
});
I get the following output:
FAIL just-a-test/adding.test.ts
● Test suite failed to run
Cannot find module '@monorepo/some-library' from 'adding.test.ts'
1 | import { CONSTANT } from '@monorepo/some-library';
2 |
> 3 | jest.mock('@monorepo/some-library', () => ({ CONSTANT: 'stubbed constant' }));
| ^
4 |
5 | describe('adding', () => {
6 | it('works', () => {
at Resolver._throwModNotFoundError (../node_modules/jest-resolve/build/resolver.js:427:11)
at Object.<anonymous> (adding.test.ts:3:6)
using babel as a transformer with their module resolver plugin this situation seems to work okay.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels