首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Jest错误无法定位模块....映射为:

Jest错误无法定位模块....映射为:
EN

Stack Overflow用户
提问于 2019-08-01 19:08:39
回答 4查看 14.7K关注 0票数 11

我尝试在VueJSQuasar framework中使用Jest。我编写简单的测试:

代码语言:javascript
运行
复制
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);
  });
});

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

代码语言:javascript
运行
复制
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)

但是,我不明白为什么我会得到这个错误。我检查了一下,path /home/user/git/my_project/client/src/pages/configurations/components/是正确的,我的类在那里。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2019-08-01 19:24:29

我写了这个:

代码语言:javascript
运行
复制
import GetUserDictionaryDataComponent from '@/pages/configurations/components/GetUserDictionaryDataComponent';
import Component from '@/pages/configurations/components/Component';

这对我很有效。

票数 2
EN

Stack Overflow用户

发布于 2020-02-20 22:51:46

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

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

希望这对任何人都有帮助

票数 6
EN

Stack Overflow用户

发布于 2021-02-08 04:21:59

如果您只想指向package.json所在的路径,请保持<rootDir>原样。

我想我的webpack也有类似的问题。对我来说,我还没有读完Jest文档,我认为<rootDir>是根目录路径的某种占位符。这不是..。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57307668

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档