使用开玩笑和柏树与打字稿引起断言和开玩笑的错误

发布于 2025-02-06 19:46:05 字数 178 浏览 1 评论 0原文

在使用错误。为什么我们在与Jest一起工作时面临类型错误和

While using [email protected] with Jest, we are facing Assertion and JestMarchers typescipt errors. Why are we facing typescipt errors while working with Jest and [email protected] in the some project?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没企图 2025-02-13 19:46:06

使用 [email  procationed] with jest] with jest,我们面临的类型错误。有解决方案。

开玩笑和柏树正在使用相同的库,因此在编写单元测试时,这可能会在嘲笑中引起打字条问题。

为了解决这个问题,我们需要两个tsconfig.json文件。一个用于root tsconfig.json,另一个用于

root tsconfig.json文件中的./cypress/tsconfig.json。
另外,在root tsconfig.json文件中,请确保添加类型:“ type”:[“ jest”,“@types/testing-library__jest-dom”]。
请调查root tsconfig.json文件。
tsconfig.json

    "compilerOptions": {
        ....
        ...
        "types": ["jest", "@types/testing-library__jest-dom"],
        
    },
    "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "next-additional.d.ts"],
    "exclude": ["node_modules", "cypress", "__mocks__", "/email-server", "cypress.config.ts"]
}

在./cypress/tsconfig.json文件中,请确保您将root tsconfig.json文件扩展了,然后将cypress.config.ts添加到文件中。
另外,您还需要确保不排除.cypress/tsconfig.json文件中的柏树。
请调查以下内容./cypress/tsconfig.json文件。

./ cypress/tsconfig.json

    "extends": "../tsconfig.json",
    "compilerOptions": {
        "types": ["cypress"]
    },
    "include": [
        "../node_modules/cypress",
        "./**/*.ts",
        "../cypress.config.ts"],
    
    "exclude": []
}

这是您需要遵循的最后一个更新;
在root项目文件夹中,您应该创建jest.d.ts文件,以添加一些类型的定义,这些定义在使用柏树时不会以某种方式提供这些定义。
如果您不提供此文件,则可以获得JestMatchers TS错误。

jest.d.ts file

    namespace jest {
        interface Matchers<R> {
            toWorkProperly(a: number): R;
        }
    }
}

export {};

注意:如果您的项目的柏树版本小于cypress@10,您需要首先将柏树版本升级到 [email&nbsp; procearted] 通过遵循默认的默认CYPRESS迁移建议。

While using [email protected] with Jest, we are facing typescript errors. There are solutions for that.

Jest and Cypress are using same libraries so this can cause typescript problems in test files in Jest while writing unit tests.

To solve this problem we need two tsconfig.json files. One is for root tsconfig.json and the another one for ./cypress/tsconfig.json

In the root tsconfig.json file be sure that you excluded cypress and cypress.config.ts file.
Also in the root tsconfig.json file be sure that add types: "types": ["jest", "@types/testing-library__jest-dom"].
Please investigate root tsconfig.json file.
tsconfig.json

    "compilerOptions": {
        ....
        ...
        "types": ["jest", "@types/testing-library__jest-dom"],
        
    },
    "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "next-additional.d.ts"],
    "exclude": ["node_modules", "cypress", "__mocks__", "/email-server", "cypress.config.ts"]
}

In the ./cypress/tsconfig.json file, be sure that you extended root tsconfig.json file and you add cypress.config.ts to file.
Also you need to be sure that you do not exclude cypress in .cypress/tsconfig.json file.
Please investigate following ./cypress/tsconfig.json file.

./cypress/tsconfig.json

    "extends": "../tsconfig.json",
    "compilerOptions": {
        "types": ["cypress"]
    },
    "include": [
        "../node_modules/cypress",
        "./**/*.ts",
        "../cypress.config.ts"],
    
    "exclude": []
}

This is the last update you need to follow;
In the root project folder you should create jest.d.ts file to add some type definitions which Jest does not provide somehow while working with cypress.
If you do not provide this file you can get JestMatchers ts errors.

jest.d.ts file

    namespace jest {
        interface Matchers<R> {
            toWorkProperly(a: number): R;
        }
    }
}

export {};

Note: If your project's cypress version less than cypress@10 you need to first upgrade cypress version to [email protected] by following default cypress migration suggestions.

半衾梦 2025-02-13 19:46:06

遇到了同样的问题,我删除了cypress.config.ts文件,ran jest test成功,并添加了cypress.config.ts归档。它在这些步骤之后开始工作

Had the same issue, I deleted the cypress.config.ts file, ran jest test with success, and added the cypress.config.ts file back in. It started working after those steps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文