Skip to content

Commit dab110a

Browse files
committed
Update
1 parent d78647e commit dab110a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/_env/mocks/redis.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const onReconnecting = [];
88
let createClientError = false;
99
let connectError = false;
1010
let subscribeError = false;
11+
let counter = {};
1112

1213
const client = {
1314
connect: jest.fn(() => {
@@ -37,12 +38,28 @@ const client = {
3738
return Promise.resolve();
3839
}),
3940
off: jest.fn(),
41+
get: jest.fn((key) => {
42+
return counter[key];
43+
}),
44+
set: jest.fn((key, value) => {
45+
counter[key] = value;
46+
return "OK";
47+
}),
48+
incr: jest.fn((key) => {
49+
counter[key]++;
50+
return counter[key];
51+
}),
52+
decr: jest.fn((key) => {
53+
counter[key]--;
54+
return counter[key];
55+
}),
4056
subscribe: jest.fn((channel, cb) => {
4157
if (subscribeError) {
4258
subscribeError = false;
4359
throw new Error("subscribe error");
4460
}
4561
onSubscribe.push(cb);
62+
return Promise.resolve();
4663
}),
4764
sSubscribe: jest.fn(),
4865
pSubscribe: jest.fn(),
@@ -55,6 +72,7 @@ const client = {
5572
for (const on of onSubscribe) {
5673
on(message, channel);
5774
}
75+
return Promise.resolve();
5876
}),
5977
error: jest.fn((err) => {
6078
for (const on of onError) {

0 commit comments

Comments
 (0)