【问题标题】:Jest error Could not locate module .... mapped as:开玩笑错误找不到模块....映射为:
【发布时间】:2019-12-09 23:18:35
【问题描述】:

我尝试将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/ 是正确的,我的课程在那里。

【问题讨论】:

    标签: vue.js jestjs quasar-framework


    【解决方案1】:

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

    "\\.(css|less)$": "&lt;rootDir&gt;/__mocks__/styleMocks.js" 但我的文件名为styleMock.js

    希望这对任何人都有帮助

    【讨论】:

      【解决方案2】:

      保持 &lt;rootDir&gt; 原样,如果您只想指向 package.json 所在的路径。

      我以为我的 webpack 也有类似的问题。对我来说,我没有读完 Jest 文档,并认为 &lt;rootDir&gt; 是我的根目录路径的某种占位符。这不是……

      【讨论】:

        【解决方案3】:

        这是我写的:

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

        它对我有用。

        【讨论】:

          【解决方案4】:

          骆驼案重要

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

          【讨论】:

            猜你喜欢
            • 2021-05-02
            • 2021-05-30
            • 1970-01-01
            • 2020-12-21
            • 1970-01-01
            • 1970-01-01
            • 2019-07-27
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多