reactjs - Graphql:Typescript + Jest + Relay + Jest 似乎无法集成在一起
问题描述
我正在测试使用 Typescript 和 Relay 构建的 React 应用程序。当我尝试测试继电器供电组件时,出现以下错误:
Unexpected invocation at runtime. Either the Babel transform was not set up, or it failed to identify this call site. Make sure it is being used verbatim as `graphql`.
我关注 .babelrc 文件:
{
"presets": ["@babel/env", "@babel/react"],
"plugins": ["relay",
[
"transform-relay-hot",
{
"schema": "./schema.graphql",
"watchInterval": 2000,
"verbose": true
}
]
]
}
并遵循 Jest 配置:
module.exports = {
roots: ["<rootDir>/src"],
transform: {
"^.+\\.tsx?$": "ts-jest",
},
testRegex : "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
moduleFileExtensions : ["ts", "tsx", "js", "jsx", "json", "node"],
transformIgnorePatterns : ["node_modules/(?!(date-fns))"],
moduleNameMapper: {
"^Apps(.*)$" : "<rootDir>/src/apps$1",
"^Pages(.*)$" : "<rootDir>/src/pages$1",
"^Components(.*)$": "<rootDir>/src/components$1",
"^Logic(.*)$" : "<rootDir>/src/logic$1",
"^Theme(.*)$" : "<rootDir>/src/theme$1",
"^Config(.*)$" : "<rootDir>/src/config$1",
"^Public(.*)$" : "<rootDir>/src/public$1",
},
globals: {
'ts-jest': {
tsConfig: "tsconfig.json",
// diagnostics: false
}
},
setupTestFrameworkScriptFile: "./src/test/test.setup.ts"
};
我在这里错过了什么吗?
解决方案
不确定这个问题是否仍然相关,但这是我所拥有的。
我使用ts-jest
. 我花了几天的时间。基本上切换到babel-jest
解决了这个问题。jest.config.js
module.exports = {
...
transform: {
"\\.[jt]sx?$": "babel-jest",
...
},
...
globals: { // if necessary
'jest': { // don't forget to change `ts-jest` to `jest` here
babelConfig: true
}
}
}
推荐阅读
- jquery - 如何在播出日期选择器日历中突出显示当前周
- c# - UWP:找不到类型或命名空间名称“TensorFloat”
- javascript - 多个文件上的打字稿命名空间
- python - 如何在 3dsMax 中实现相机平移?
- json - Spring Web Socket Session 抛出 Jackson 异常
- node.js - 如何在 SAP Cloud Platform 中使用 NodeJS 的 Destination
- android - android中的自定义组项目recyclerview
- android - Android HTTP 请求失败
- ncurses - ncurses:如何刷新单个面板
- oracle - Sharepoint webpart 2016 和 oracle db 9i