我正在尝试使用 jest 在我的项目中运行一些测试,但是在与测试本身无关的过程中我收到了错误代码。更像是依赖项或节点表达兼容性错误
`● Test suite failed to run
TypeError: pathRegexp is not a function
6 |
7 |
> 8 | app.use(express.json());
| ^
9 |
10 | const authRoutes = require('./routes/auth');
11 | const userRoutes = require('./routes/users');
at new Layer (bankly/node_modules/express/lib/router/layer.js:45:17)
at Function.use (bankly/node_modules/express/lib/router/index.js:475:17)
at Function.lazyrouter (bankly/node_modules/express/lib/application.js:151:18)
at Function.use (bankly/node_modules/express/lib/application.js:221:8)
at Object.<anonymous> (bankly/app.js:8:5)
at Object.<anonymous> (bankly/__tests__/routes.test.js:6:13)
Test Suites: 1 failed, 1 passed, 2 total
Tests: 5 passed, 5 total
Snapshots: 0 total
Time: 0.397 s, estimated 1 s
Ran all test suites.`
我已经检查这个错误有一段时间了,似乎找不到解决方案,已经尝试更新依赖项,降级其中一些。重新安装express和node。这些似乎都不起作用。
我尝试将正则表达式路径降级为较旧的版本,但它仍然无法正常工作
● Test suite failed to run
TypeError: pathRegexp is not a function
11 | items.push(data2);
12 |
> 13 | router.get("/", function (req, res) {
| ^
14 | return res.json(items);
15 | });
16 |
at new Layer (node_modules/express/lib/router/layer.js:45:17)
at Function.route (node_modules/express/lib/router/index.js:505:15)
at Function.get (node_modules/express/lib/router/index.js:520:22)
at Object.<anonymous> (routes/items.js:13:8)
at Object.<anonymous> (app.js:3:20)
at Object.<anonymous> (app.test.js:6:13)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.249 s
// inside the package.json
{
"name": "routing_middleware",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.2",
"express": "^4.19.2",
"path-to-regexp": "^0.1.7"
},
"devDependencies": {
"supertest": "^6.3.4"
}
}
版本