Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Support for jest-mock-extended's calledWith mocks #292

Closed
1 task done
laurence-hudson-mindfoundry opened this issue Apr 16, 2024 · 1 comment
Closed
1 task done
Labels
enhancement New feature or request

Comments

@laurence-hudson-mindfoundry

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

In jest-mock-extended there is a mockFn that can be used as a replacement for jest.fn. It produces mocks that have a .calledWith interface for more fluent mocking, i.e. thisMock.doSomething.calledWith(123).mockReturnValue(456). Currently the mocks created by automock are vanilla jest mocks. It would be really nice to be able to get mocks with calledWith via the TestBed unitRef.get interface (with type safey).

Describe the solution you'd like

jest-mock-extended's MockProxy type (which includes calledWith) appears be a sub type of vanilla jest mocks, so it might be plausible to adopt it for all of automock's jest mocking without breaking changes. But it would probably be cleaner to add a "mocker" argument to TestBed (although the generic typing required for this might get ugly).

What is the motivation / use case for changing the behavior?

Gain the advantages of both automock and jest-mock-extended without loosing the cleanness of automock's interfaces.

@omermorad
Copy link
Member

Hello @laurence-hudson-mindfoundry 👋

That is actually a very good and interesting idea. I'm familiar with jest-mock-extended because it was the first mock function we used in Automock (and has been removed at version 2.0.0). However, we did not expose the "extended" functionality (like calledWith and others), but we do plan to do so it in the near future, utilizing native functionality rather than external libraries (e.g. 'jest-mock-extended').

I hope to provide an update here soon! Thanks!

@omermorad omermorad added the enhancement New feature or request label Apr 22, 2024
@automock automock locked and limited conversation to collaborators May 30, 2024
@omermorad omermorad converted this issue into discussion #327 May 30, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants