小编Suh*_*hah的帖子

TypeError:无法读取未定义的属性“ cwd”

我正在使用Jest和React-Testing-Library编写测试用例,当我运行测试脚本时,它将引发如下错误

TypeError: Cannot read property 'cwd' of undefined

现在我已经尝试了几乎所有方法来解决此问题,但没有找到导致此问题的原因

我试图更改config,即使我已经使用--no-cache运行,但再次引发相同的错误

这是我的配置文件

const { defaults } = require("jest-config");

module.exports = {
    testEnvironment: "node",
    // setupFiles: [
    //     "<rootDir>/../apollo-server-env/dist/index.js"
    // ],
    preset: "ts-jest",
    testMatch: null,
    testRegex: ".*test*\\.(ts|tsx|js)$",
    testPathIgnorePatterns: [
        "/node_modules/",
        "/dist/"
    ],
    transform: {
        "\\.(gql|graphql)$": "jest-transform-graphql",
        "\\.(ts|tsx)$": "ts-jest",
        // Use our custom transformer only for the *.js and *.jsx files
        "\\.(js|jsx)?$": "./transform.js",
        // future need to test with
        //  "^.+\\.(js|jsx|ts|tsx)$": "./transform.js",
        // ".+\\.(css|styl|less|sass|scss)$": "jest-css-modules-transform"
    },
    roots: [
        "packages",
        "packages-modules",
        "servers"
    ],
    moduleFileExtensions: …
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs jestjs graphql

3
推荐指数
2
解决办法
3019
查看次数

标签 统计

graphql ×1

javascript ×1

jestjs ×1

reactjs ×1

typescript ×1