Jest error Could not locate module .... 映射为:

新手上路,请多包涵

我尝试将 JestVueJSQuasar framework 一起使用。我写了简单的测试:

 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);
  });
});

但它不能正常工作。当我尝试运行我的测试时,出现错误:

 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)

但是,我不明白为什么会出现此错误。我检查过,路径 /home/user/git/my_project/client/src/pages/configurations/components/ 是正确的,我的课程在那里。

原文由 All_Safe 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.2k
2 个回答

我写了这个:

 import GetUserDictionaryDataComponent from '@/pages/configurations/components/GetUserDictionaryDataComponent';
import Component from '@/pages/configurations/components/Component';

它对我有用。

原文由 All_Safe 发布,翻译遵循 CC BY-SA 4.0 许可协议

对我来说,这是最简单的错字。我在用

"\\.(css|less)$": "<rootDir>/__mocks__/styleMocks.js" 但我的文件被命名为 styleMock.js

希望这可以帮助任何人

原文由 Pierre Ferry 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题