diff --git a/src/index.js b/src/index.js index 68cc30ad5..8519ddcd2 100644 --- a/src/index.js +++ b/src/index.js @@ -173,8 +173,8 @@ class RedisMock extends EventEmitter { return pipeline.exec(callback) } - duplicate() { - const mock = new RedisMock() + duplicate(override) { + const mock = new RedisMock({ ...this.options, ...override }); mock.expires = this.expires mock.data = this.data mock.channels = this.channels diff --git a/test/integration/commands/duplicate.js b/test/integration/commands/duplicate.js new file mode 100644 index 000000000..67224b2ca --- /dev/null +++ b/test/integration/commands/duplicate.js @@ -0,0 +1,15 @@ +import Redis from 'ioredis' + +describe('duplicate', () => { + it('prerequisites', () => { + expect(new Redis().options.lazyConnect).toBe(false) + }) + it('should preserve options', () => { + const redis = new Redis({ lazyConnect: true }) + expect(redis.duplicate().options.lazyConnect).toBe(true) + }) + it('should handle overrides', () => { + const redis = new Redis({ lazyConnect: true }) + expect(redis.duplicate({ lazyConnect: false }).options.lazyConnect).toBe(false) + }) +})