Skip to content

Commit

Permalink
fix(duplicate): preserve options as well as accept overrides (#1234)
Browse files Browse the repository at this point in the history
fixes #1207
  • Loading branch information
erictheswift committed Jan 30, 2023
1 parent 15a464a commit 284f711
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/integration/commands/duplicate.js
Original file line number Diff line number Diff line change
@@ -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)
})
})

0 comments on commit 284f711

Please sign in to comment.