Javascript 与木偶师开玩笑TypeError:无法创建属性'_称为';关于数字';11';

Javascript 与木偶师开玩笑TypeError:无法创建属性'_称为';关于数字';11';,javascript,jestjs,puppeteer,Javascript,Jestjs,Puppeteer,测试的错误日志: 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

测试的错误日志:

 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
服务器端package.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"
  }
}
{
  "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"
  }
}
客户端package.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"
  }
}
{
  "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"
  }
}
有人能帮我吗?我尝试了很多解决方案,但没有一个对我有效:(

如果我从测试文件中的所有测试中删除一个测试,它可以正常工作 如果我再次添加删除的测试,则会发生错误
这个错误可能是因为时间问题而发生的吗?
我和jest有一个类似的问题: 在我不断地向“XXXX.test.js”文件添加更多测试之后,在某个时候,除了一些测试之外,它失败了,错误是“无法创建属性”\u调用了数字“10”。因此,我尝试增加超时时间,但没有帮助

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


我想我们都在尝试做同样的事情(Udemy)

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

我更改了安装文件中的jest
超时设置,它对我有效:

将这一行添加到
setup.js
中,用于jest:
jest.setTimeout(30000);

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


在每个测试文件的顶部添加“Number.prototype._called={};”对我来说很有用。重构这行代码的一种方法是将其添加到测试目录中的setup.js文件中,而不是将其添加到每个测试文件中。

这很有效!谢谢