You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support for jest-mock-extended's calledWith mocks #292
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.
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').
Activity
omermorad commentedon Apr 22, 2024
Hello @laurence-hudson-mindfoundry 👋
That is actually a very good and interesting idea. I'm familiar with
jest-mock-extendedbecause 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 (likecalledWithand 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!