Jest error Could not locate module .... mapped as:

All_Safe picture All_Safe · Aug 1, 2019 · Viewed 8.6k times · Source

I try use Jest with VueJS and Quasar framework. I write simple test:

import { GetUserDictionaryDataComponent, Component } from '@/pages/configurations/components/';

describe('GetUserDictionaryDataComponent', () => {
  it('should get correct type', () => {
    const component = new GetUserDictionaryDataComponent(undefined);
    expect(component.getComponentType()).toBe(Component.LEAF);
  });
});

But It not work correctly. When I try run my test, I get error:

Test suite failed to run

    Configuration error:

    Could not locate module @/pages/configurations/components/ mapped as:
    /home/user/git/my_project/client/src/pages/configurations/components/.

    Please check your configuration for these entries:
    {
      "moduleNameMapper": {
        "/^@\/(.*)$/": "/home/user/git/my_project/client/src/$1"
      },
      "resolver": null
    }

    > 1 | import { GetUserDictionaryDataComponent, Component } from '@/pages/configurations/components/';
        | ^
      2 | 
      3 | describe('GetUserDictionaryDataComponent', () => {
      4 |   it('should get correct type', () => {

      at createNoMappedModuleFoundError (node_modules/@jest/core/node_modules/jest-resolve/build/index.js:472:17)
      at Object.<anonymous> (src/tests/pages/configurations/components/GetUserDictionaryDataComponent.spec.js:1:1)

But, I don't uderstand, why I get this error. I checked, path /home/user/git/my_project/client/src/pages/configurations/components/ is correct, my classes there.

Answer

Pierre Ferry picture Pierre Ferry · Feb 20, 2020

For me it was the simplest typo. I was using

"\\.(css|less)$": "<rootDir>/__mocks__/styleMocks.js" but my file was named styleMock.js

Hope this helps anyone