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

add functionality to safe mock functions #17

Closed
regevbr opened this issue Mar 29, 2020 · 3 comments · Fixed by #19
Closed

add functionality to safe mock functions #17

regevbr opened this issue Mar 29, 2020 · 3 comments · Fixed by #19

Comments

@regevbr
Copy link
Contributor

regevbr commented Mar 29, 2020

Example of the feature:

type MyFunction = (x: string) => Promise<number>;

const mocked = mockFn<MyFunction>();
mocked.mockResolvedValue(5);
regevbr added a commit to regevbr/jest-mock-extended that referenced this issue Mar 29, 2020
regevbr added a commit to regevbr/jest-mock-extended that referenced this issue Mar 29, 2020
regevbr added a commit to regevbr/jest-mock-extended that referenced this issue Apr 12, 2020
@marchaos
Copy link
Owner

Hey. I'm in 2 minds about this. I feel that jest already provides this functionality already. I haven't checked, but assume jest.fn does not have a generic Param for doing this?

@regevbr
Copy link
Contributor Author

regevbr commented Jun 11, 2020

Hi @marchaos,
your calledWithFn also have generic params, same as jest.fn but I want your library capabilities, and I want auto inference of types and not passing them manually...

The following example can't be achieved by jest

 type MyFn = (x: number, y: number) => Promise<string>;
 const fn = mockFn<MyFn>();
 fn.calledWith(1, 2).mockReturnValue('str');

@marchaos
Copy link
Owner

Yep. Makes sense. I'll merge this in for now, but am planning on adding "mock" to the best object as "mockType" so might need to do something similar with this at that point. I will keep it backwards compatible!

marchaos added a commit that referenced this issue Jun 11, 2020
add functionality to safe mock functions #17
Beraliv pushed a commit to Beraliv/jest-mock-extended that referenced this issue May 1, 2024
* ⬆️ Update dependencies

* ♻️ Do not use vitest global
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

Successfully merging a pull request may close this issue.

2 participants