小编Mat*_*att的帖子

使用TypeScript进行Jest:TypeError:environment.teardown不是函数

当我尝试使用Jest运行测试时出现此错误:

 FAIL  src/__tests__/jokeGenerator.test.tsx
  ? Test suite failed to run

    TypeError: environment.teardown is not a function

      at node_modules/jest-runner/build/run_test.js:230:25
Run Code Online (Sandbox Code Playgroud)

我在这里遇到了一个可能的解决方案:如何解决TypeError:environment.teardown不是一个函数?

但在做了以下建议:删除我的yarn.lock文件,node_modules文件夹,从我的package.json中删除Jest,然后再用纱线重新安装所有内容 - 我遇到了一个新问题:

  ? Test suite failed to run

    TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string

      at assertPath (path.js:39:11)
      at Object.relative (path.js:1173:5)
      at Object.getCacheKey (node_modules/ts-jest/dist/utils/get-cache-key.js:15:16)
Run Code Online (Sandbox Code Playgroud)

我有一种预感,以前解决方案对其他解决方案起作用的原因是因为他们使用create-react-app然后安装了与之相冲突的版本.如果是这种情况,那么上述解决方案不适用于我的问题,因为我没有使用create-react-app.

所以我重新安装了jest和@ types/jest,现在有了同样的初始问题......

这是我的webpack配置:

module.exports = {
  entry: './src/index.tsx',
  devServer: {
    contentBase: __dirname + '/dist/',
  },
  module : {
    rules: [
      {
        test: /\.tsx?$/,
        exclude: /node_modules/,
        use: {
          loader: …
Run Code Online (Sandbox Code Playgroud)

javascript node.js typescript jestjs

5
推荐指数
2
解决办法
3585
查看次数

标签 统计

javascript ×1

jestjs ×1

node.js ×1

typescript ×1