diff --git a/.gitignore b/.gitignore index a004e18d..965f6413 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .nyc_output .vscode +.idea coverage junit lib diff --git a/src/commands-utils/emitDisconnectEvent.js b/src/commands-utils/emitDisconnectEvent.js new file mode 100644 index 00000000..86eaf7cc --- /dev/null +++ b/src/commands-utils/emitDisconnectEvent.js @@ -0,0 +1,5 @@ +export default function emitConnectEvent(redisMock) { + process.nextTick(() => { + redisMock.emit('end') + }) +} diff --git a/src/index.js b/src/index.js index d1bb402b..92083d4c 100644 --- a/src/index.js +++ b/src/index.js @@ -8,6 +8,7 @@ import createCommand, { Command } from './command' import * as commands from './commands' import * as commandsStream from './commands-stream' import emitConnectEvent from './commands-utils/emitConnectEvent' +import emitDisconnectEvent from './commands-utils/emitDisconnectEvent' import contextMap, { createContext } from './context' import { createData } from './data' import { createExpires } from './expires' @@ -201,6 +202,8 @@ class RedisMock extends EventEmitter { removeFrom(this.channels) removeFrom(this.patternChannels) + + emitDisconnectEvent(this) // no-op } diff --git a/test/integration/disconnect.js b/test/integration/disconnect.js index 5f0dc55b..bbafb8b0 100644 --- a/test/integration/disconnect.js +++ b/test/integration/disconnect.js @@ -1,8 +1,15 @@ import Redis from 'ioredis' describe('disconnect', () => { - it('should be available, but do nothing', () => { + it('should be available and emit "end" event', async () => { const redis = new Redis({}) + const events = [] + redis.on('end', () => events.push('end')) + expect(redis.disconnect()).toBe(undefined) + + await new Promise(resolve => setImmediate(resolve)); + + expect(events).toEqual(['end']) }) })