在使用摩卡咖啡运行测试用例时,我会得到以下错误
ReferenceError: describe is not defined
at Object.<anonymous> (/myproject/test/unit/physicalperson.spec.js:12:1)有人知道为什么会发生这种事吗?
package.json
"scripts": {
"test": "mocha"
},physicalperson.spec.js
const request = require('supertest-as-promised');
const chai = require('chai');
const app = require('../../src/server');
const expect = chai.expect;
const PHYSICALPERSON_ENDPOINT = '/api/physicalperson';
describe('Integration tests for Physical Person', () => {
describe('\nFAIL Cases - Physical Person', () => {
it('should return 404 status if physical person is not present on database', (done) => {
request(app)
.get(`${PHYSICALPERSON_ENDPOINT}/xxap`)
.then((res) => {
expect(res.statusCode).to.equal(404);
done();
})
.catch((err) => {
done(err);
});
});
});
});


我试过什么
我在所以中看到了一些线程,我还尝试了下面的代码,但同样的错误也发生了。
var mocha = require('mocha')
var describe = mocha.describe
var it = mocha.it
var assert = require('chai').assert
describe('#indexOf()', function() {
it('should return -1 when not present', function() {
assert.equal([1,2,3].indexOf(4), -1)
})
})发布于 2019-10-17 13:52:58
我想,您正在使用节点命令运行测试,例如:无法使用node fileName.test.js mocha来理解它的测试文件,您必须使用mocha命令运行它,如下所示。
mocha fileName.test.js或者简单地在package.json文件中配置,以便使用**npm run test**命令运行测试;示例如下。
"test": "istanbul cover --report cobertura --report html ./node_modules/mocha/bin/_mocha -- --reporter mocha-jenkins-reporter -t 180000 \"test/unit/*.js\"",上面的命令也用伊斯坦布尔生成覆盖报告。
https://stackoverflow.com/questions/47398837
复制相似问题