admin管理员组文章数量:1414888
I want to test my Expo React Native app with Jest and @testing-lib/react-native
.
I have the following set up in my package.json
.
"jest": {
"preset": "jest-expo",
"moduleDirectories": [
"node_modules",
"test-utils"
]
},
And my folder structure looks like this:
├──node_modules/
├──test-utils/
├──src/
└──package.json
src/
contains the test files. I'm testing my configuration with this simple test at 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,
});
});
Where assert
is in test-utils/index.js
:
const assert = ({
given = undefined,
should = '',
actual = undefined,
expected = undefined,
} = {}) => {
it(`given ${given}: should ${should}`, () => {
expect(actual).toEqual(expected);
});
};
export { assert };
If I run my tests I get the error:
Cannot find module 'test-utils' from 'index.test.js'
Why is that? I mean I have configured the moduleDirectories
key?
本文标签: javascriptmoduleDirectories key does not make it possible to import my test utilsStack Overflow
版权声明:本文标题:javascript - moduleDirectories key does not make it possible to import my test utils - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745163733a2645571.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论