cdm*_*dmt 0 reactjs jestjs react-testing-library
我创建了一个反应打字稿应用程序npx create-react-app . --template typescript
我添加了一个基本测试文件
import '@testing-library/jest-dom/extend-expect'
const sumPositiveNumbers = (num1:number, num2: number) => {
return num1 + num2
}
describe('when test pass', () => {
test('should return an answer', () => {
expect(sumPositiveNumbers(4,5).toBe(9))
})
})
Run Code Online (Sandbox Code Playgroud)
我收到错误
TypeError: sumPositiveNumbers(...).toBe is not a function
Run Code Online (Sandbox Code Playgroud)
package.json 看起来像
{
"name": "test",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/node": "^12.0.0",
"@types/react": "^16.9.53",
"@types/react-dom": "^16.9.8",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.1",
"typescript": "^4.0.3",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么,我做错了什么
我不断收到这样的错误,但我正在使用我认为可以工作的 create-react-app
Ben*_*ght 10
您的右括号位于错误的位置。它应该是:
expect(sumPositiveNumbers(4,5)).toBe(9)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3434 次 |
| 最近记录: |