0
我想用supertest
来测试我的koa
API路线和检查什么在DynamoDB之前和之后,以确保端点做了什么之意。supertest前和使用后的await检查DynamoDB
// app related
const pool = require('../../src/common/pool');
const app = require('../../server');
// for testing
const uuid = require('uuid');
const supertest = require('supertest');
// listen on port 40002
const request = supertest.agent(app.listen(4002));
describe('test',() => {
it.only('should', async (done) => {
debugger;
const id = uuid.v4().replace(/-/g, '');
await pool.add(id, 'data', 30);
return request
.get('/api/1')
.expect(204)
// .then(async (res) => {
// .then((res) => {
.end((res) => {
// still returns 'data' instead of 'dataNew' after the route is hit
const record = await pool.get(id);
debugger;
done();
});
});
});
在上面的代码中,我创建一个数据库中的记录,然后我打的终点,我尝试了then()
和end()
链接功能再次检查分贝。终点将只是data
至dataNew
和then()
函数,它仍会返回原始的data
。
关于如何验证db中新记录的任何想法?
参考文献:
- 3210 - 在TLDR底部,该解决方案是使用
co
。我试过这个,并有问题可能导致我使用await
而不是发电机。