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

Testing overloaded methods is hard #1315

Open
Shiuyin opened this issue Mar 14, 2024 · 1 comment
Open

Testing overloaded methods is hard #1315

Shiuyin opened this issue Mar 14, 2024 · 1 comment

Comments

@Shiuyin
Copy link

Shiuyin commented Mar 14, 2024

I want to test some code that i wrote with SVG.js. I need to use jest.toHaveBeenCalledWith() to see if specific circle methods have been called with the correct params. Unfortunately, .circle() is an overloaded function. TS does not know what is the correct overloaded function one to spy on. So by default it always chooses the last signature known.

There are many posts on the internet that describe the issue like:

The recommended standard is for the most general signature to be the last one. Unfortunately, .circle() with just the size param is not the last one, even though it is the more general one, causing jest to choose the wrong overload in my tests. I managed to workaround it with the 2nd link above, but it's not the greatest of solution.

In might be beneficial to check the typings and make sure that the most general overloaded signature is always the last one.

@Fuzzyma
Copy link
Member

Fuzzyma commented Jun 18, 2024

sorry for the late response. Feel free to create a PR to adapt the typings to your needs. If there is a better way of writing it, a PR is absolutely welcome!

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