jestjs - 如何修复抛出“找不到模块”错误的 Jest 测试?
问题描述
对于我在运行 Jest 测试时遇到的错误,我将不胜感激。
当我在 Mozilla 的 Devtools 上工作时,可以在这里找到我正在运行的代码:
https://hg.mozilla.org/mozilla-central/file
我在文件 devtools/client/debugger/src/components/Editor/SearchBar.js 中添加了一个导入语句。文件在这里: https ://hg.mozilla.org/mozilla-central/file/tip/devtools/client/debugger/src/components/Editor/SearchBar.js
导入语句是:
从“devtools/shared/plural-form”导入 { PluralForm };
我在代码更改中使用此功能。出于某种原因,这会在测试“Editor.spec.js”和“SearchBar.spec.js”中产生错误。
错误是:无法从“SearchBar.js”中找到模块“devtools/shared/plural-form”
当我运行代码时,该函数运行良好,但 Jest 很难解析模块。
任何帮助,将不胜感激!
我尝试在配置文件中添加到 modulePaths。
无法从“SearchBar.js”中找到模块“devtools/shared/plural-form”
37 | import type SourceEditor from "../../utils/editor/source-editor";
38 |
> 39 | const { PluralForm } = require("devtools/shared/plural-form");
| ^
40 | // import { PluralForm } from "devtools/shared/plural-form";
41 |
42 | function getShortcuts() {
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:221:17)
at Object.<anonymous> (src/components/Editor/SearchBar.js:39:24)
解决方案
推荐阅读
- c - 在makefile中实现子目录
- html - 如何通过 Angular 中另一个页面 (html) 上的按钮或链接的单击事件来更改 div 的可见性
- azure-devops - 缓存自定义任务?
- javascript - TypeError undefined 不是函数
- html - 链接需要双击激活-如何使它只有一个?角 5
- angularjs - mdDialog 不会显示 templateUrl
- python - 如何自己加入熊猫数据框?
- javascript - 在 ReactJS 中遇到多个活动状态的问题
- powershell - Powershell SQL查询变量
- javascript - 具有意外结果的阵列拼接