Closed carloshpb closed 1 year ago
I have no clue what Riverpod is, sorry. Your code looks correct. But the error message doesn't match the code (it says it fails at line 76, but it also fails in when
, but in your code the only when
is at line 109).
Could you please make the code match the error message? It would also be great, if you could try to minimize the code. Thanks.
Sorry about that. The error actually occurred at the line :
verifyInOrder([
listener.call(argThat(isNull), argThat(isZero)),
]);
I've actually changed the test code to see if I could fix it, to this :
verifyInOrder([
listener.call(argThat(isNull), 0),
listener.call(0, 2),
]);
And then the message came :
Matching call #1 not found. All calls: MockListener<int>.call(null, 0)
it always happens when I use the verify. Because the stubbed methods are not returning the correct values, like :
when(getOnboardingMessagesUseCase.execute())
.thenReturn(defaultOnboardMessages);
The defaultOnboardMessages has some messages defined at the beginning of the test. But when calling the methods getOnboardingMessagesUseCase.execute , it always come to an empty list.
Ok, if you get an empty list from a call to getOnboardingMessagesUseCase.execute()
, despite setting an expectation, it looks like your expectation doesn't work and you are getting the default dummy value (which is an empty list for List
).
You can switch this mock to throw on missing stubs to verify this (MockSpec<GetOnboardingMessagesUseCase>(onMissingStub: OnMissingStub.throwException)
).
Note that execute
has an optional argument, so when(getOnboardingMessagesUseCase.execute())
will only match the calls to execute
either without arguments or with an argument being null
. If you want to stub all calls to execute
, you have to use when(getOnboardingMessagesUseCase.execute(any))
.
Hm.. but the argument of execute
has type void
... is that intentional? There might be some edge case connected to that.
@carloshpb any update? Can we close this? Looks like WAI to me.
@yanok sorry for the delay .... I had an urgent task to solve this week. Soon I'll look after this better and answer you.
Ok, I'm going to close it, seems to be WAI to me. Feel free to re-open with more details.
any updates on that?
When I try to test a NotifierProvider of Riverpod, I have to stub some inner providers that are used within the test class. The problem is that the methods never call the results that I've put to return with the stub.
SAMPLE CODE
ERROR MESSAGE
I've tested it in different ways (I know that storing the _onboardingMessages as an attribute in the controller class is not ideal, but it didn't work in any other way either).
Can you please guide me if I am doing something wrong here, or is this a potential issue with the way Riverpod and Mockito are interacting?
Thanks.