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
I see in #16 and #19 there was work done to capture arguments which is great for verification, however I'd like to set my mock to always return the nth argument.
This is useful for repository style functions that save an entity and return it again.
In Java mockito this was achieved with thenAnswer()
// Expect specified method call to return the nth argument
public static <T> void returnArgument(T methodCall, int argumentIndex) {
when(methodCall).thenAnswer(invocation -> invocation.getArguments()[argumentIndex]);
}
The beauty of this in the TS stack is we can also mimick behaviour of returning a new object with additional fields if required, via spread. If there is a simple workaround in the mean time or if I've missed something then I'd love to hear it.
Thanks for the great lib!
The text was updated successfully, but these errors were encountered:
I see in #16 and #19 there was work done to capture arguments which is great for verification, however I'd like to set my mock to always return the nth argument.
This is useful for repository style functions that save an entity and return it again.
In Java mockito this was achieved with
thenAnswer()
The beauty of this in the TS stack is we can also mimick behaviour of returning a new object with additional fields if required, via spread. If there is a simple workaround in the mean time or if I've missed something then I'd love to hear it.
Thanks for the great lib!
The text was updated successfully, but these errors were encountered: