[英]Not able to find Done in mocha test cases using Chai-http
I'm learning to write test cases using mocha and chai for the node application,I had written the below test case我正在学习使用 mocha 和 chai 为节点应用程序编写测试用例,我已经编写了以下测试用例
let chai = require('chai');
let chaiHttp = require('chai-http');
const should = chai.should;
const expect = chai.expect;
const server = "http:\\localhost:3000"
chai.use(chaiHttp);
describe('Create Login and Register', () => {
it('should login using credentials', () => {
chai.request(server)
.get('/register')
.send()
.then((res: any) => {
res.should.have.status(200);
done();
}).catch((err: any) => { done(err) })
})
})
but it shows the read swiggle below the done();但它在 done() 下方显示了读取摆动; function function
do i need to add some types for it to get working what is that i'm missing,i tried to install chai-http again but still same issue我是否需要添加一些类型才能使其正常工作我缺少什么,我尝试再次安装 chai-http 但仍然是同样的问题
done
is passed in as the first argument to your test function. done
作为测试 function 的第一个参数传入。
describe('Create Login and Register', () => {
it('should login using credentials', (done) => { // <-- here
chai.request(server)
.get('/register')
.send()
.then((res: any) => {
res.should.have.status(200);
done();
}).catch((err: any) => { done(err) })
})
})
Although, because you are using a Promise
chain, you should just return the chain instead.虽然,因为您使用的是Promise
链,所以您应该只返回该链。
describe('Create Login and Register', () => {
it('should login using credentials', () => {
return chai.request(server)
.get('/register')
.send()
.then((res: any) => {
res.should.have.status(200);
}); // a rejected promise will fail the test automatically
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.