Created
October 20, 2020 17:29
-
-
Save sibelius/8c1d25df74ceca6147c43bbe017bea65 to your computer and use it in GitHub Desktop.
this is a hacky to make ioredis-mock work well with pubsub - related to https://github.com/stipsan/ioredis-mock/issues/773
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jest.mock('ioredis', () => { | |
const Redis = require('ioredis-mock'); | |
if (typeof Redis === 'object') { | |
// the first mock is an ioredis shim because ioredis-mock depends on it | |
// https://github.com/stipsan/ioredis-mock/blob/master/src/index.js#L101-L111 | |
return { | |
Command: { _transformer: { argument: {}, reply: {} } }, | |
}; | |
} | |
let instance = null; | |
// second mock for our code | |
return function (...args) { | |
if (instance) { | |
return instance.createConnectedClient(); | |
} | |
instance = new Redis(args); | |
return instance; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment