I'm trying to pass Mockito's argument matchers into nested objects values. I've successfully used something like this so far:
when(object.getData(any, any, userId: anyNamed("userId"))).thenAnswer((_) async => response);
However now I need to use any
or anyNamed
for nested values. The following code:
when(adapterMock.fetch(
RequestOptions(
method: anyNamed("method"),
path: "orders",
),
any,
any,
)).thenAnswer((_) async =>response);
Gives an error:
Invalid argument(s): An ArgumentMatcher was declared as named method, but was not passed as an
argument named method.
BAD: when(obj.fn(anyNamed: "a")))
GOOD: when(obj.fn(a: anyNamed: "a")))
Is there any correct way to provide nested arguments matchers?