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

Type-safe callback args #1058

Open
dstoyanoff opened this issue Mar 6, 2024 · 2 comments
Open

Type-safe callback args #1058

dstoyanoff opened this issue Mar 6, 2024 · 2 comments

Comments

@dstoyanoff
Copy link

Feature request

Make callback accept a generic argument to type the the args returned in the Expression

@dvabuzyarov
Copy link
Owner

dvabuzyarov commented Mar 6, 2024

Hello,
@dstoyanoff
could you provide an example of the issue? It would help a lot to stay on the same page

@dstoyanoff
Copy link
Author

dstoyanoff commented Mar 6, 2024

Hey, sure.

Imagine I have a database repository and I want to mock a getById(id: string): User function for multiple users. I could of course do that for every user, but since callback give us access to args, we could do it dynamically:

repoMock
   .setup(repo => repo.getById('user_1'))
   .callback(({ args }) => ({
     id: args[0],
     // ...some other props
   }))

Since args are of type any[], there is no type-safety in reading them, so it would be nice if we could do that the same way as it is for It.Is<T>

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