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

mocking imports broken by typescript 3.9 #32

Closed
jacobg opened this issue Nov 17, 2020 · 1 comment
Closed

mocking imports broken by typescript 3.9 #32

jacobg opened this issue Nov 17, 2020 · 1 comment

Comments

@jacobg
Copy link

jacobg commented Nov 17, 2020

Since typescript version 3.9, mocking imports is no longer supported as-is, due to this commit:
microsoft/TypeScript#32264

There is discussion on this issue regarding sinon mocking also broken by this commit:
microsoft/TypeScript#38568

It's a bit tldr; for me. Do you have any ideas for a workaround?

EmandM pushed a commit that referenced this issue Nov 19, 2020
@EmandM
Copy link
Owner

EmandM commented Nov 19, 2020

ImportMock.mockClassInPlace() has now been added to the library. This will give you the same functionality as the original if you are simply mocking functions on classes.

Unfortunately the key functionality behind much of this library is based on the idea of swapping the original export with a mock export at the point the file is exported. This new Typescript change blocks that behaviour by ensuring all exports are only gettable so there is no way to set them during runtime.

If mockClassInPlace() doesn't solve your problem, you can look into running an older version of Typescript, or changing the way your project is compiled to avoid this Typescript issue.

@EmandM EmandM closed this as completed Nov 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants