-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Needs a version to be in line with [email protected] #195
Comments
my current ugly workaround:
|
Can you show a broader exemple on how that solution works? |
Thanks to @jpike88 I managed to create a fairly clean, but hopefully temporary, workaround: // ** redis-mock-v4.ts ** //
// redis-mock has not been updated for node-redis v4 yet, but the main changes
// in the API are camelCase names and promises instead of callback, so we can work around it.
// https://github.com/yeahoffline/redis-mock/issues/195
import redis from "redis-mock";
// @ts-expect-error Work-around redis-mock types reporting incorrectly as v4 redis.
import { RedisClient } from "@types/redis";
import { promisify } from "util";
const client = redis.createClient() as unknown as RedisClient;
const setEx = promisify(client.setex).bind(client);
const v4Client = {
connect: () => undefined,
get: promisify(client.get).bind(client),
del: promisify(client.del).bind(client),
flushAll: promisify(client.flushall).bind(client),
setEx: promisify(client.setex).bind(client),
expire: promisify(client.expire).bind(client),
mGet: promisify(client.mget).bind(client),
pSetEx: (key: string, ms: number, value: string) =>
setEx(key, ms / 1000, value),
// Add additional functions as needed...
};
export default { ...redis, createClient: () => v4Client };
// ** my-unit-tests.ts ** //
import redis from "./redis-mock-v4"; // used to be from "redis-mock"
jest.mock("redis", () => redis); |
@wardds thanks for this and @jpike88 I'm trying as above but keep getting:
|
New Redis is around the corner, and this mock lib is breaking in two clear cases:
The text was updated successfully, but these errors were encountered: