Код: Выделить всё
Details:
node_modules/components/src/ui/label.js:2
import { jsx as _jsx } from "react/jsx-runtime";
SyntaxError: Cannot use import statement outside a module
> 1 | import { Label } from '@/ui/label';
| ^
2 |
3 | export function HelloWorld() {
4 | return (
< /code>
Полный компонент, на который он смотрит, выглядит так (src/hello-world.tsx
Код: Выделить всё
import { Label } from '@/ui/label';
export function HelloWorld() {
return (
Hello World
);
}
< /code>
Затем у меня есть настройка шутки, которая выглядит так (__tests__/hello-world.test.tsx
Код: Выделить всё
import { render } from '@testing-library/react';
import { HelloWorld } from '../src/hello-world';
describe('Renders the dashboard', () => {
it('Load Hello World Component', () => {
const { getByText } = render();
expect(getByText('Hello World')).toBeInTheDocument();
});
});
Код: Выделить всё
import path from 'path';
const __dirname = new URL('.', import.meta.url).pathname;
export default {
moduleFileExtensions: ['tsx', 'ts', 'jsx', 'js', 'json', 'node'],
testMatch: ['/__test(s)?__/**/*.(spec|test).[jt]s?(x)'],
setupFilesAfterEnv: [path.join(__dirname, 'jest.setup.ts')],
rootDir: './',
testEnvironment: 'jsdom',
transform: {
'\\.[jt]sx?$': [
'babel-jest',
{
configFile: path.join(__dirname, 'babel.config.cjs'),
},
],
},
transformIgnorePatterns: [
'/node_modules/(?!next-auth|jose|@panva/hkdf|uuid|preact-render-to-string|preact)',
'^.+\\.module\\.(css|sass|scss)$',
],
};
Примечание: используется, как при изменении предустановки/плагина К тому, чего не существует, он бросает ошибку, говоря, что не может найти предустановку/плагин
Код: Выделить всё
module.exports = {
presets: [
// 'next/babel',
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-react',
'@babel/preset-typescript',
],
// plugins: [],
plugins: ['@babel/plugin-transform-modules-commonjs'],
};
Подробнее здесь: https://stackoverflow.com/questions/794 ... jest-tests