Created
August 31, 2018 09:11
-
-
Save nidble/16c8f9043759edf93ac2eedf6dc63ead to your computer and use it in GitHub Desktop.
redis mock require example
This file contains 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
const Module = require('module') | |
const originalRequire = Module.prototype.require | |
const Redis = require('ioredis-mock') | |
Module.prototype.require = function () { | |
const filePath = Array.prototype.concat.apply([], arguments)[0] | |
if (!filePath.includes('setup/redis')) { | |
return originalRequire.apply(this, arguments) | |
} | |
const mockRedis = new Redis({ | |
data: { | |
'comments:stats.total': 'ciao' | |
} | |
}) | |
return mockRedis | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment