Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Export interface changed (jest) #1442

Closed
artur-ma opened this issue Oct 6, 2021 · 8 comments · Fixed by #1445
Closed

Export interface changed (jest) #1442

artur-ma opened this issue Oct 6, 2021 · 8 comments · Fixed by #1445

Comments

@artur-ma
Copy link

artur-ma commented Oct 6, 2021

Not sure what happened, but after upgrading to ioredis@4.27.10
jest cant fully mock ioredis module

ioredis@4.27.10

> jest.genMockFromModule('ioredis').Cluster
undefined

ioredis@4.27.9

> jest.genMockFromModule('ioredis').Cluster
ƒ Cluster() {return mockConstructor.apply(this,arguments);}
@luin
Copy link
Collaborator

luin commented Oct 6, 2021

4.27.10 doesn't seem to introduce any changes that can affect this: v4.27.9...v4.27.10

@artur-ma
Copy link
Author

artur-ma commented Oct 6, 2021

@luin yeah, I saw the diff, I dont know what is the reason
u can look on the isolated example prepared by me

https://github.com/artur-ma/ioredis-bug/tree/main

@artur-ma
Copy link
Author

artur-ma commented Oct 6, 2021

I think its related to the version of typescript u used for version x.10

this is x.10 index.js

var cluster_1 = require("./cluster");
Object.defineProperty(exports, "Cluster", { enumerable: true, get: function () { return cluster_1.default; } });

this is x.9

var cluster_1 = require("./cluster");
exports.Cluster = cluster_1.default;

@liaoliaots
Copy link

same issue ✿◡‿◡

@liaoliaots
Copy link

liaoliaots commented Oct 7, 2021

@artur-ma
Because jest automock does not mock getters and setters.

But we can mock manually via:

// __mocks__/ioredis.ts
import { Cluster, Redis } from 'ioredis';

const mockIORedis = jest.createMockFromModule<{ default: Redis }>('ioredis/built/redis').default;
Reflect.defineProperty(mockIORedis, 'Cluster', {
    enumerable: true,
    value: jest.createMockFromModule<{ default: Cluster }>('ioredis/built/cluster').default
});

export default mockIORedis;

@artur-ma
Copy link
Author

Hey, thanks, but the point that this is a breaking change, we have hundreds on tests that rely on these mocks :(

@luin
Copy link
Collaborator

luin commented Oct 11, 2021

@artur-ma You are correct. Sorry for didn't notice that. Created a fix!
@liaoliaots Thanks for the solution here.

@ioredis-robot
Copy link
Collaborator

🎉 This issue has been resolved in version 4.27.11 🎉

The release is available on:

Your semantic-release bot 📦🚀

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants