gpt4 book ai didi

javascript - 如何整合 Flow 和 Jest?

转载 作者:行者123 更新时间:2023-12-02 14:45:20 25 4
gpt4 key购买 nike

我想人们很少会同时使用 Jest 和 Flow,但 Jest 似乎无法识别 Flow 的输入标记。

当我运行jest时,我收到错误消息:

 FAIL  __tests__/components/Ui/CheckboxWithLabel.test.js
● Test suite failed to run

/home/cargobr/Projetos/Estudos/Terminator-React-Starter-Kit/src/app/components/CheckboxWithLabel.js: Unexpected token (6:12)
4 | export default class CheckboxWithLabel extends React.Component {
5 | state: {isChecked: boolean};
> 6 | onChange: function;
| ^
7 | setState: function;
8 | props: {labelOn: boolean, labelOff: boolean};
9 |

我刚刚安装了 flow-typed 和 flow-typed install jest@20.0.4,问题仍然存在。

部分package.json

{
"dependencies": {
"react": "^15.3.2",
"react-dom": "^15.3.2",
"react-router-dom": "^4.0.0",
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-core": "^6.24.1",
"babel-eslint": "^7.1.1",
"babel-jest": "^20.0.3",
"babel-loader": "^6.4.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-flow": "^6.23.0",
"babel-preset-react": "^6.24.1",
"enzyme": "^2.9.1",
"eslint": "^3.18.0",
"eslint-plugin-react": "^6.10.0",
"jest": "^20.0.4",
"react-addons-test-utils": "^15.6.0",
"react-test-renderer": "^15.6.1",
"regenerator-runtime": "^0.10.5",
"style-loader": "^0.16.1",
"webpack": "^2.3.3",
"webpack-dev-server": "^2.4.2"
},
"scripts": {
"start": "webpack-dev-server",
"test": "jest"
},
"jest": {
"testRegex": "__tests__/components/.*./*.test.js"
}
}

eslintrc

{
"extends": ["eslint:recommended", "plugin:react/recommended"],
"parser": "babel-eslint",
"plugins": [
"react"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
}
},
"env": {
"jest": true
}
}

最佳答案

我猜这是因为函数应该是函数? (第一个字母大写)

关于javascript - 如何整合 Flow 和 Jest?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45640863/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com