-
Notifications
You must be signed in to change notification settings - Fork 77
Description
It's pretty cool that you can add expectations over time, like this:
expect(UserAPI, :get_user, 1, fn 123 -> {:ok, %{id: 123} end)
expect(UserAPI, :get_user, 1, fn 456 -> {:ok, %{id: 456} end)
In such a way you can define expectations that the UserAPI.get_user will be called exactly twice, once with 123 and once with 456 argument.
Problem appears when you don't care about the exact order of function invocations, but you still care about how many and with what arguments they will be called. For example, imagine my code that retrieves users, does it in parallel (e.g. using Task.async). Then I'm not sure anymore if User API will first receive the 123 or 456 in the request.
Yet, I want to verify that it had been called twice - once with 123, once with 456, in any order.
Is that possible with mox?
For example, in JavaScript's Jest library it is possible in such a way:
expect(getUserMock).toHaveBeenCalledTimes(2);
expect(getUserMock).toHaveBeenCalledWith(123);
expect(getUserMock).toHaveBeenCalledWith(456);or like this
expect(getUserMock.calls).toEqual( expect.arrayContaining([123, 456]) );