Cannot use import statement outside a module in jest test on Ionic import

I’m currently facing an issue while trying to test my react application using Jest.
While I try to test a component that imports an Ionic module, I have the following error message “import statement outside a module”.
This is my test file :

import { render, cleanup } from '@testing-library/react';
import { IonImg } from '@ionic/react';
import '@ionic/react-test-utils';

describe('<IonImg />', () => {
 afterEach(cleanup);

 it('renders an image with a valid src', () => {
    const { getByAltText } = render(
      <IonImg src="http://placehold.it/200x200" alt="Test image"></IonImg>
    );
    expect(getByAltText('Test image')).toHaveAttribute('src', 'http://placehold.it/200x200');
 });
}); 

The error occurs on this line :
import { IonImg } from '@ionic/react';

I tried several things like :

But nothing has made it work, can someone help me please ?

Leave a Comment