0
所以我试过查找这个bug,但我似乎无法找到迎合我的bug的答案。我使用摩卡和chai-http来测试一些API。我只是使用他们相应的RESTFUL方法(POST,GET,PUT)来检查端点并检查响应(非常简单)。问题是,单独使用我的测试套件(如果我一次只运行一个套件),但是当我使用我的gulp命令运行它们时...我对某些测试用例(“回调函数”那些在如果你熟悉摩卡如果钩)回调不是函数 - 摩卡/猫鼬
这里是我得到的错误:
Uncaught TypeError: callback.apply is not a function
at Immediate.<anonymous> (node_modules/mongoose/lib/model.js:3683:16)
at Immediate._onImmediate (node_modules/mongoose/node_modules/mquery/lib/utils.js:137:16)
这里是我的目录,我的测试案例所在的结构:
test
backend
assignments_tests.js
application_tests.js
courses_test.js
&我有一个以下的大酒杯文件:
// Set the environment variable for the test cases to point to production
gulp.task('set-testing-env', function() {
return process.env.NODE_ENV = 'production';
})
// gulp task for backend
gulp.task('test-backend', ['set-testing-env'], function() {
return gulp.src('test/backend/**/*.js', {read: false})
.pipe(mocha({
reporter: 'spec',
timeout: 60000
}))
.on('error', function(err) {
// console.log(err);
process.exit();
});
});
&终于我的测试案例的样本:
describe("testing GET" ....
before(function(done) {
... setting up stuff here and calling done ...
})
describe("get courses information and courses offered", function() {
it("gets a courses information", function(done) {
const endpoint = test.endpoint + "/courseInfo/" + test.course
chai.request(app)
.get(endpoint)
.end(function(err, res) {
expect(err, "Error hitting endpoint").to.be.null;
expect(res, "Expected data in json format").to.be.json;
expect(res, "Expected status to be 200").to.have.status(200);
expect(res.body, "Expected course info!").to.have.length(1);
expect(res.body[0],"Missing keys").to.have.all.keys(courseInfo);
done();
})
})
})
describe("testing POST" ...
before(function(done) {
... setting up and calling done ...
})
describe(...
it(...)
})
})
我也不太清楚为什么我得到一个回调不是一个函数错误。 :( 任何帮助,将不胜感激