Skip to content

Testing overloaded methods is hard #1315

@Shiuyin

Description

@Shiuyin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions