I am using Jest to run some tests and have come across an issue with one of the modules I am using. The issue is that I am trying to import a module that is not compiled down when built. What I mean by not compiled down is that the imports
are left at the top of the file I am trying to import into another. Here is what I mean:
jest.mock('@my-org/my-package/dist/browser');
import * as NTracking from '@my-org/my-package/dist/browser';
import generateStubs from '../test-jest/fixtures/client-stubs';
import testedController from './controller';
describe('client controller b', () => {
const stubs = generateStubs();
let mockWindow;
beforeEach(() => {
mockWindow = stubs.mockWindow;
NTracking.mockImplementation(() => stubs.nTracking);
});
afterEach(() => {
jest.clearAllMocks();
});
it('should construct', () => {
new testedController(mockWindow);
});
});
The issue I have is on line 2 where I am trying to import NTracking
from @my-org/my-package/dist/browser
. The file I am trying to import looks like this:
browser.js
import somePackage from 'some-packge/some-function';
import someOtherPackage from 'some-other-packge/some-function';
When running the test I get the following error:
SyntaxError: Unexpected identifier
This is due to the word import
obviously not being a native javascript definition.
My question is this - how could I configure Jest to compile the problematic module (my-package
) before running the tests?