Thanks for the amazing library! This is exactly what I have been looking for and I hope something like this gets added to the jest core codebase soon.
I have a lot of boilerplate code that I would like to reduce and I think with a small modification to this library I can make that happen. I often mock libraries that I use in my codebase to mock the return values from the library. For instance, in my code I might use an Azure sdk and write tests that will mock the return value of the SDK and test how my code behaves. It's possible to mock those classes easily with this library, but the code is a bit hard to read so cleaning it up would be nice.
Internally, the when function would call jest.spyOn when it sees 2 arguments and then return the when object as usual. I realize this example is trivial, but i sometimes have 3 different functions that im mocking and I think the code looks much cleaner with the second approach.
Another approach could be to export a new "when" function with a different name that calls jest.spyOn internally.
Thanks for the amazing library! This is exactly what I have been looking for and I hope something like this gets added to the jest core codebase soon.
I have a lot of boilerplate code that I would like to reduce and I think with a small modification to this library I can make that happen. I often mock libraries that I use in my codebase to mock the return values from the library. For instance, in my code I might use an Azure sdk and write tests that will mock the return value of the SDK and test how my code behaves. It's possible to mock those classes easily with this library, but the code is a bit hard to read so cleaning it up would be nice.
current
Would you consider a PR for the
when
function to accept a second argument so I can do something like this:Internally, the when function would call
jest.spyOn
when it sees 2 arguments and then return the when object as usual. I realize this example is trivial, but i sometimes have 3 different functions that im mocking and I think the code looks much cleaner with the second approach.Another approach could be to export a new "when" function with a different name that calls
jest.spyOn
internally.Let me know what you think.
Keep up the great work!