I'm trying to run an integration test with redis and jest.
It always throws the "Jest has detected the following 1 open handle potentially keeping Jest from exiting:" error when running with --detectOpenHandles.
It doesn't hang so the socket is closing, but how do I write it so it doesn't throw that warning?
My code
import redis from 'redis';
let red: redis.RedisClient;
beforeAll(() => {
red = redis.createClient();
});
afterAll((done) => {
red.quit(() => {
done();
});
});
test('redis', (done) => {
red.set('a', 'b', (err, data) => {
console.log(err);
red.get('a', (err, data) => {
console.log(data);
done();
});
});
});
Warning
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● TCPWRAP
3 |
4 | beforeAll(() => {
> 5 | red = redis.createClient();
| ^
6 | });
7 |
8 | afterAll((done) => {
at RedisClient.Object.<anonymous>.RedisClient.create_stream (node_modules/redis/index.js:251:31)
at new RedisClient (node_modules/redis/index.js:159:10)
at Object.<anonymous>.exports.createClient (node_modules/redis/index.js:1089:12)
at Object.<anonymous>.beforeAll (src/sockets/redis.integration.test.ts:5:17)
Running the compiled code with regular jest throws the same warning. The compiled code looks nearly identical.