5

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?

uminder
  • 23,831
  • 5
  • 37
  • 72
Limbou
  • 369
  • 1
  • 9

2 Answers2

4

It appears that using nested matchers is not possible in mockito. I ended up restructuring my project a little bit so I don't need to use such matchers anymore.

Limbou
  • 369
  • 1
  • 9
0

use headers:captureAnyNamed("headers"),