0

Im trying to setup tests for my company's app. The app runns perfectly, but when i run tests i get the following error:

 Cannot find module @myCompany/custom-react-components from 'src/contentArea/detailPages/components/DetailPageSections.tsx'

This is my test

import { render, screen } from "@testing-library/react"
import App from "./App"

describe("App component", () => {
    test("Renders App component correctly", () => {
        render(<App />)
        const appComponent = screen.getByText(/Click me/i)
        expect(appComponent).toBeInTheDocument()
    })
})

I also tried to configure the moduleMappers in the jest.config file which looks like this currently

 moduleNameMapper: {
        "^@myCompany/custom-react-components/components$": "<rootDir>/node_modules/@myCompany/custom-react-components/dist/components/index.js",
        "^@myCompany/custom-react-components$": "<rootDir>/node_modules/@myCompany/custom-react-components/dist/index.js",
    },

We are using custom react components which are hosted on aws code artifact. Also if I try to test components which do not include custom components the tests run smooth. I have the feeling that he module mappers are not set correctly, but I tried every possible solution, without success.

What I also noticed is that the custom components which are located like this:

@myCompany/custom-components/dist/components

And some are structured like this:

@myCompany/custom-components/dist/components/tileView

The second one seems to be the issue.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.