【发布时间】:2021-12-26 05:48:19
【问题描述】:
我想从正文中保存一些数据,并将其用于我的测试中的下一个请求。我正在做一个发布请求并取回一个ID。我想用这个 id 在其他测试中获取数据。
我的代码如下所示:
it('/auth/register (POST)', async () => {
const test = await request(app.getHttpServer())
.post('/api/auth/register')
.send({username: "Zoe"})
.expect(201)
token = test.body.token
})
令牌正在设置并且代码运行,但是我的玩笑测试不会停止,我会收到错误:
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
我知道我可以执行 forceExit,但我想彻底清除并理解问题。
当我做一个开玩笑的返回方法时,它正在工作..但是我知道如何将身体存储在某个地方..
it('/auth/register (POST)', () => {
request(app.getHttpServer())
.post('/api/auth/register')
.send({username: "Zoe"})
.expect(201)
})
【问题讨论】:
标签: javascript testing jestjs nestjs supertest