I introduced in react tests after i wrote app with react and typescript. I tried to test anything for start but counted with big number of errors at once.
Here is my default component App which i tried to test. (The Navigation component consist from one fiction Link if its required)
import { Route, Routes } from 'react-router-dom';
import { MainPage } from './pages/MainPage';
import { Navigation } from './components/Navigation';
function App() {
return (
<div className="bg-yellow-200">
<Navigation/>
<Routes>
<Route path='/' element={<MainPage/>} />
</Routes>
</div>
);
}
export default App;`
And here is my App.test.tsx just for being
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
And my terminal log starts with this
"Jest encountered an unexpected token.."
and with such details
Details: SyntaxError: Cannot use import statement outside a module
> 1 | import axios from 'axios';
| ^
2 | import { IDeal } from '../models/DealModel';
3 |
4 | const API_URL = 'http://localhost:3001';
I had tried to attune my tsconfig, add different babel and jest packeges + create their configs and adjust package.json but it gave no resolve in the problem.
So, what kind of illness i have in my mind, why i deserved it?
Nikita is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.