愿所有的美好和期待都能如约而至

模块方向键不允许导入我的测试实用程序

发布时间:  来源:互联网  作者:匿名  标签:error moduleDirectories key does not make it possible to import my test utils ex  热度:37.5℃

本文介绍了模块方向键不允许导入我的测试实用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用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键?

勇敢去编程!

勇敢的热爱编程,未来的你一定会大放异彩,未来的生活一定会因编程更好!

TOP