使用木偶师开玩笑 类型错误:无法在数字 '11' 上创建属性'_called'



测试错误日志:

PASS  tests/header.test.js (8.099s)
✓ the header section has the correct text (2260ms)
✓ clicking login starts OAuth flow (2511ms)
✓ When signed in,  shows logout button (2851ms)

RUNS  tests/blogs.test.js
Test Suites: 1 passed, 1 of 2 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        11s, estimated 38s
console.error node_modules/jsdom/lib/jsdom/virtual-console.js:29
Error: Uncaught [TypeError: Cannot create property '_called' on number '11']
at reportException (/home/sh4d0w/Desktop/Node-Advance/AdvancedNodeStarter/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
at Timeout.callback [as _onTimeout] (/home/sh4d0w/Desktop/Node-Advance/AdvancedNodeStarter/node_modules/jsdom/lib/jsdom/browser/Window.js:680:7)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7) TypeError: Cannot create property '_called' on number '11'
FAIL  tests/blogs.test.js (11.265s)-Advance/AdvancedNodeStarter/node_modules/mo  when logged in
✓ can see blog create form (2923ms)
And using valid inputs
✓ submitting take user to review screen (3365ms)
✓ submitting then saving adds blogs to index page (3635ms)
And using invalid inputs
✕ the form shows an error message (842ms)
● when logged in › And using invalid inputs › the form shows an error message
TypeError: Cannot create property '_called' on number '11'

at node_modules/mongodb-core/lib/topologies/shared.js:224:25
at Timeout.callback [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:678:19)
Test Suites: 1 failed, 1 passed, 2 total
Tests:       1 failed, 6 passed, 7 total
Snapshots:   0 total
Time:        12.005s, estimated 38s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! server@1.0.0 test: `jest`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the server@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/sh4d0w/.npm/_logs/2020-08-03T07_48_03_329Z-debug.log

当我运行此测试时,在服务器端发生此错误
具有react dev服务器日志的节点:

[1] Compiled successfully!
[1] 
[1] You can now view client in the browser.
[1] 
[1]   Local:            http://localhost:3000/
[1]   On Your Network:  http://192.168.0.105:3000/
[1] 
[1] Note that the development build is not optimized.
[1] To create a production build, use npm run build.
[1] 
[1] Proxy error: Could not proxy request /api/blogs from localhost:3000 to http://localhost:5000.
[1] See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNRESET).
[1] 
[1] [HPM] Error occurred while trying to proxy request /api/blogs from localhost:3000 to http://localhost:5000 (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)
[1] Proxy error: Could not proxy request /api/blogs from localhost:3000 to http://localhost:5000.
[1] See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNRESET).
[1] 
[1] [HPM] Error occurred while trying to proxy request /api/blogs from localhost:3000 to http://localhost:5000 (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)
[1] Proxy error: Could not proxy request /api/blogs from localhost:3000 to http://localhost:5000.
[1] See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNRESET).
[1] 
[1] [HPM] Error occurred while trying to proxy request /api/blogs from localhost:3000 to http://localhost:5000 (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)
[0] [nodemon] restarting due to changes...
[0] [nodemon] starting `node index.js`
[0] [nodemon] restarting due to changes...
[0] [nodemon] starting `node index.js`
[0] Listening on port 5000

服务器端软件包.json文件

{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"jest": {
"setupTestFrameworkScriptFile": "./tests/setup.js",
"verbose": true,
"testURL": "http://localhost/"
},
"scripts": {
"start": "node index.js",
"server": "nodemon index.js --ignore tests",
"client": "npm run start --prefix client",
"dev": "concurrently "npm run server" "npm run client"",
"build": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client",
"heroku-postbuild": "npm run build",
"test": "jest"
},
"author": "",
"license": "ISC",
"dependencies": {
"aws-sdk": "^2.188.0",
"body-parser": "^1.17.2",
"concurrently": "^3.5.0",
"cookie-session": "^2.0.0-beta.2",
"express": "^4.15.3",
"jest": "^22.4.4",
"migrate-mongoose": "^3.2.2",
"mongoose": "^4.11.1",
"nodemon": "^1.11.0",
"passport": "^0.3.2",
"passport-google-oauth20": "^2.0.0",
"path-parser": "^2.0.2",
"puppeteer": "^5.2.1",
"redis": "^2.8.0",
"uuid": "^3.2.1"
}
}

客户端软件包.json文件

{
"name": "client",
"version": "0.1.0",
"private": true,
"proxy": {
"/auth/*": {
"target": "http://localhost:5000"
},
"/api/*": {
"target": "http://localhost:5000"
}
},
"dependencies": {
"axios": "^0.16.2",
"materialize-css": "^0.100.2",
"react": "^16.0.0-alpha.13",
"react-dom": "^16.0.0-alpha.13",
"react-redux": "^5.0.5",
"react-router-dom": "^4.1.1",
"react-scripts": "1.0.10",
"redux": "^3.7.1",
"redux-form": "^7.0.1",
"redux-thunk": "^2.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}

有人能帮我吗?我尝试了很多解决方案,但没有一个对我有效:(

如果我从测试文件中的所有测试中选择一个测试,它可以正常工作如果我再次添加删除的测试,则会发生错误这个错误可能是因为时间问题而发生的吗

将这段代码放在每个测试文件的顶部Number.prototype._called = {};

我在设置文件中更改了jesttimeOut设置,它对我有效:

将此行添加到setup.js中以开玩笑:
jest.setTimeout(30000);

更改超时解决了部分问题:(

添加";Number.protype._called={}"重构这行代码的一种方法是将它添加到测试目录中的setup.js文件中,而不是将其添加到每个测试文件中。

我对jest也有类似的问题:在我不断向'XXXX.test.js'文件添加更多测试后,在某个时候,除了一些测试之外,它会失败,并出现错误"无法在数字"10"上创建属性"_called";。所以,我试着增加超时时间,但无济于事。

我的解决方案是:我制作了另一个测试文件"XXXX_part2.tests.js",然后将所有新测试复制到该文件中并运行测试。这为我解决了问题。

我认为我们都在努力做同样的事情(Udemy(

最新更新