Skip to content

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

Closed

Description

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.

Activity

  1. omermorad commented on Apr 22, 2024

    @omermorad
    Collaborator

    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!

  2. locked and limited conversation to collaborators on May 30, 2024
  3. converted this issue into a discussion #327 on May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions