Skip to content
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

Redis.Cluster can't mocked by Jest #1308

Closed
icebob opened this issue Mar 23, 2021 · 6 comments · Fixed by #1309
Closed

Redis.Cluster can't mocked by Jest #1308

icebob opened this issue Mar 23, 2021 · 6 comments · Fixed by #1309
Labels

Comments

@icebob
Copy link

icebob commented Mar 23, 2021

Hello,

I struggle with an issue in my unit tests (where Jest mock the ioredis classes) with the latest v4.24.3 version.
In the previous versions the following unit tests pass:

jest.mock("ioredis");

const Redis = require("ioredis");

describe("Test Redis", () => {
	it("create Redis instance", () => {
		const client = new Redis();
		expect(client).toBeInstanceOf(Redis);
		expect(Redis).toBeCalledTimes(1);
	});

	it("create Redis Cluster instance", () => {
		const client = new Redis.Cluster();
		expect(client).toBeInstanceOf(Redis.Cluster);
		expect(Redis.Cluster).toBeCalledTimes(1);
	});
});

Result
image

But with v4.24.3 I've got errors for the same tests:
image

Do you have any idea what is the problem and how can I fix it? Thanks in advance.

@luin
Copy link
Collaborator

luin commented Mar 23, 2021

Hi @icebob, what was the ioredis version in the first screenshot?

@icebob
Copy link
Author

icebob commented Mar 23, 2021

v4.24.2, the previous version.

@icebob
Copy link
Author

icebob commented Mar 23, 2021

In the meantime, I'm trying debugging the issue and I think the problem comes from this changes: bf3fe29#diff-d5a4b3a0309f2337144861084c1014523cced561eb722cb9684c63f5e41e0567
Because in the compiled JS the Cluster changed to a getter and it seems Jest can't traverse the getters.
image

ioredis-robot pushed a commit that referenced this issue Mar 24, 2021
## [4.24.4](v4.24.3...v4.24.4) (2021-03-24)

### Bug Fixes

* minor compatibility issues caused by TypeScript upgrade ([#1309](#1309)) ([c96139a](c96139a)), closes [#1308](#1308)
@ioredis-robot
Copy link
Collaborator

🎉 This issue has been resolved in version 4.24.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@icebob
Copy link
Author

icebob commented Mar 24, 2021

It was quick, thanks @luin, I really appreciate it. Now it works fine.

@tomijais
Copy link

tomijais commented Apr 7, 2021

I have the same problem with the Redis constructor in the new version

image

janus-dev87 added a commit to janus-dev87/ioredis-work that referenced this issue Mar 1, 2024
## [4.24.4](redis/ioredis@v4.24.3...v4.24.4) (2021-03-24)

### Bug Fixes

* minor compatibility issues caused by TypeScript upgrade ([#1309](redis/ioredis#1309)) ([c96139a](redis/ioredis@c96139a)), closes [#1308](redis/ioredis#1308)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants