Skip to content

Instantly share code, notes, and snippets.

@nidble
Created August 31, 2018 09:11
Show Gist options
  • Save nidble/16c8f9043759edf93ac2eedf6dc63ead to your computer and use it in GitHub Desktop.
Save nidble/16c8f9043759edf93ac2eedf6dc63ead to your computer and use it in GitHub Desktop.
redis mock require example
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