Skip to content
Advertisement

Module not found even though it is imported

When I run this test:

describe('<Reissue />', () => {
    it('calls reissue service', () => {
        const handleClose = () => null;
        const disableButton = () => null;
        const showPrompt = true;
        const po = '123456';

        const wrapper = shallow(<Reissue handleClose={handleClose} disableButton={disableButton} showPrompt={showPrompt} pol={pol}/>);
        expect(wrapper.find('.reissue').length).toBe(1);
    });    
});

I get this error:

Cannot find module 'src/services/ReissueService/ReissueService' from 'Reissue.tsx'

      14 | interface State {
      15 |     confirmButton: boolean;
    > 16 |     confirmed: boolean;
      17 | }
      18 |
      19 | export class Reissue extends React.Component<Props, State> {

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:169:17)
      at Object.<anonymous> (src/components/reissue/ReissueCert.tsx:16:27)

Reissue.tsx does import ReissueService. Do I need to mock this and if so how do I do that?

In Reissue my import is:

import { ReissueService } from 'src/services/ReissueService/ReissueService';

and I’m exporting:

export class Reissue extends React.Component<Props, State> {...

In ReissueService I export:

export interface ReissueURL {...

export class ReissueService {...

Advertisement

Answer

I changed import { ReissueService } from 'src/services/ReissueService/ReissueService'; to import { ReissueService } from '../../services/ReissueService/ReissueService';

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement