我运行mocha test
但出现错误
Error: Cannot find module 'expect.js'
我的package.json
{
"name": "new-restexpress",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"start": "node index.js",
"test": "PORT=3007 ./node_modules/.bin/mocha test -R spec"
},
"author": "Richard Rublev",
"license": "ISC",
"devDependencies": {
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-prettier": "^3.1.3",
"expect": "^25.3.0",
"mocha": "^7.1.1",
"prettier": "^2.0.4",
"standard": "^14.3.3",
"superagent": "^5.2.2"
},
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"mongodb": "^2.2.36",
"mongoskin": "^2.1.0",
"morgan": "^1.10.0"
}
}
我看着树-d
│ ├── expect
│ │ ├── build
│ │ │ └── ts3.4
│ │ ├── build-es5
│ │ └── node_modules
│ │ ├── ansi-styles
│ │ ├── color-convert
│ │ └── color-name
为什么期望不能被识别?
答案 0 :(得分:1)
答案 1 :(得分:0)
为了使用期望,您必须安装一个允许您使用的断言库,直接安装期望对我没有用,当我遇到类似问题时,我安装了chai。像这样安装它:
npm i --save-dev chai
然后以下一种方式导入并像这样使用:
var expect = require('chai').expect;
var numbers = [1, 2, 3, 4, 5];
expect(numbers).to.be.an('array').that.includes(2);
在package.json脚本中:
{
"scripts": {
"test": "mocha"
}
}