Closed anton-johansson closed 1 year ago
Hey! Just found this library, very nice utility.
I'd love a way to set up a "default" mock using jest-when. For example:
jest-when
when(getUser).calledWith(expect.anything()).mockResolvedValue(null); when(getUser).calledWith(1).mockResolvedValue(userFixture);
But this does not seem to work. The expect.anything() does not seem to work. It works if I only have it, but not in combination with the "real" mock.
expect.anything()
As a workaround, I have to specify the "incorrect" user ID that I use in my test, but I would love to not have to do that:
when(getUser).calledWith(666).mockResolvedValue(null); when(getUser).calledWith(1).mockResolvedValue(userFixture);
Does this help?
https://github.com/timkindberg/jest-when#supports-default-behavior
Wow, I'm blind as a bat. Sorry, and thanks for the very quick response, @timkindberg!
Hey! Just found this library, very nice utility.
I'd love a way to set up a "default" mock using
jest-when
. For example:But this does not seem to work. The
expect.anything()
does not seem to work. It works if I only have it, but not in combination with the "real" mock.As a workaround, I have to specify the "incorrect" user ID that I use in my test, but I would love to not have to do that: