问题描述
我正在编写2个单元测试来测试Rest API。但是,第一次测试失败,第二次通过。 谁能指出我在这里做错了什么?我是JavaScript和Mocha的新手。谢谢!
test.js
var request = require('request');
const { response } = require('express');
it('Get Response recieved',function(done){
request('http://localhost:5000',function(err,res,body) {
expect(body).to.equal('Welcome !');
expect(response.statusCode).to.equal(200);
done();
})
})
it('Success status code',body) {
expect(response.statusCode).to.equal(200);
done();
})
})```
解决方法
您需要使用回调中的Table(
border: TableBorder.all(color: Colors.black),columnWidths: {
0: FixedColumnWidth(100.0),// fixed to 100 width
1: FlexColumnWidth(),2: FixedColumnWidth(100.0),//fixed to 100 width
},
对象来检查状态码:
res
请注意:expect(body).to.equal('Welcome !');
expect(res.statusCode).to.equal(200);
库是deprecated,您应该考虑更改为其他http库。