I'm using a create-react-app project with Typescript and Enzyme (I've also tried react-testing-library and ran into the same issue)
I'm new to React testing and trying to get basic tests working. In this case, I'm trying to test the App component which renders the Ping component. This error only occurs when trying to render a connected component, it does not occur when trying to render a stateless functional component.
When I try to make a simple render test on my App component, I get the error:
Cannot find module 'src/components/Ping' from 'index.tsx'
where index.tsx is the App component.
App.test.tsx
import { shallow } from 'enzyme'
import * as React from 'react'
import App from '..'
it('renders without crashing', () => {
shallow(<App/>)
});
App.tsx
import * as React from 'react';
import Ping from "src/components/Ping";
import './App.css';
class App extends React.Component {
public render() {
return (
<div className="App">
<header className="App-header">
<h1 className="App-title">Welcome to React</h1>
</header>
<Ping/>
</div>
);
}
}
export default App;
this error also occurred when I tried using react-testing-library with the render function.
import Ping from "./src/components/Ping", or have you set up thepathsconfiguration so thatimport Ping from "src/components/Ping"should work?