'How to use absolute path in enzyme

I use Enzyme and React 17.0.2 together

jsconfig.json

{
    "compilerOptions": {
        "baseUrl": "src"
    },
    "include": [
        "src"
    ]
}

enzymeConfig.js

import { configure } from "enzyme";
import Adapter from "@wojtekmaj/enzyme-adapter-react-17";

configure({ adapter: new Adapter() });

Login.test.js

import React from "react";
import { mount } from "enzyme";
import '../../enzymeConfig';
import Login from "components/Layout/Login/FormSide/Login";

describe('Test login form', () => {
    let wrapper;

    it("Username created correctly.", function () {
        wrapper = mount(<Login />);
        wrapper.find('input[type="text"]').simulate("change", {
            target: { value: 'something' }
        });
        expect(wrapper.state("username")).toEqual("world");
    });
});

I use absolute path in react and I haven't issue But in Enzyme I get the following error:

Cannot find module 'components/Layout/Login/FormSide/Login' from 'src/__tests__/Login.test.js'

How can i use absolute path in Enzyme?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source