近期对一个项目写单元测试后,运行时有以下提示:
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.
大概意思是说Jest不能在完成测试后正常退出。
后来将代码中发现redis连接后,没有写关闭的代码,我是用ioredis的包,查看官方文档后
https://github.com/luin/ioredis/blob/HEAD/API.md
是用
redis.disconnect()
Disconnect from Redis.
This method closes the connection immediately, and may lose some pending replies that haven’t written to client. If you want to wait for the pending replies, use Redis#quit instead.
封装好代码后,在程序停止时加入断开连接的代码。
再运行jest时,没有上面的报错了。