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