我尝试在VueJS和Quasar framework中使用Jest。我编写简单的测试:
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)但是,我不明白为什么我会得到这个错误。我检查了一下,path /home/user/git/my_project/client/src/pages/configurations/components/是正确的,我的类在那里。
发布于 2019-08-01 19:24:29
我写了这个:
import GetUserDictionaryDataComponent from '@/pages/configurations/components/GetUserDictionaryDataComponent';
import Component from '@/pages/configurations/components/Component';这对我很有效。
发布于 2020-02-20 22:51:46
对我来说,这是最简单的打字错误。我用的是
"\\.(css|less)$": "<rootDir>/__mocks__/styleMocks.js",但我的文件名为styleMock.js
希望这对任何人都有帮助
发布于 2021-02-08 04:21:59
如果您只想指向package.json所在的路径,请保持<rootDir>原样。
我想我的webpack也有类似的问题。对我来说,我还没有读完Jest文档,我认为<rootDir>是根目录路径的某种占位符。这不是..。
https://stackoverflow.com/questions/57307668
复制相似问题