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 generic functions separately for different types #39

Open
begrob opened this issue Sep 29, 2021 · 3 comments
Open

Mocking generic functions separately for different types #39

begrob opened this issue Sep 29, 2021 · 3 comments

Comments

@begrob
Copy link

begrob commented Sep 29, 2021

Hi, thanks for sharing your library.
A question - can this library be used to mock separate "generic signatures" of a generic function ?

Using your example:

export interface SomeService {
    get<T>(index: number): Observable<T>;
}

can I create separate mocks for

get<Customer>
get<User>

etc at the same time ?

@jjherscheid
Copy link
Owner

Hi,
Thank you for using the library ;-)
I haven't tried mocking 2 generic methods at the same time. I don't think it wil work at this moment because internally the mock will implement one spy on the get method. To support this feature somehow the mock should have different spies. But I don't think that's an easy solution. There should be a some kind of switch inside the spy method based on the type.
I really like the idea to support this, so I will leave this issue open for now.
If you have idea's yourself feel free to try things oud and send PR.

@begrob
Copy link
Author

begrob commented Oct 1, 2021 via email

@jjherscheid
Copy link
Owner

Hi Rob,
If you create wrappers around the methods with different names the multi spy generic mock is not needed anymore.
Basically this library just adds the Spy functionality which works based on methods names. But because I don't like strings with method names I created this library to create typesafe Spy.
When I have time myself I am still interested in trying to find a better solution, but I don't know if there is any :S...
Good luck,
Johan

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