模块方向键不允许导入我的测试实用程序
本文介绍了模块方向键不允许导入我的测试实用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用Jest和@testing-lib/react-native
测试我的EXPO Reaction Native应用程序。
我的package.json
中有以下设置。
"jest": {
"preset": "jest-expo",
"moduleDirectories": [
"node_modules",
"test-utils"
]
},
我的文件夹结构如下:
├──node_modules/
├──test-utils/
├──src/
└──package.json
src/
包含测试文件。我正在使用src/index.test.js
中的这个简单测试测试我的配置:
import { assert } from 'test-utils';
const sum = (a, b) => a + b;
describe('sum', () => {
assert({
given: 'two numbers',
should: 'add the numbers',
actual: sum(1, 3),
expected: 4,
});
});
其中assert
位于test-utils/index.js
:
const assert = ({
given = undefined,
should = '',
actual = undefined,
expected = undefined,
} = {}) => {
it(`given ${given}: should ${should}`, () => {
expect(actual).toEqual(expected);
});
};
export { assert };
如果我运行测试,则会收到错误:
Cannot find module 'test-utils' from 'index.test.js'
为什么?我的意思是我已经配置了moduleDirectories
键?