In Mockito Flutter how to write a matcher to match Any except specified?
There is an isNot
Matcher
that you can combine with other Matcher
s. So, for example, you should be able to do something like: expect(valueToTest, isNot(unwantedValue));
or expect(valueToTest, isNot(isIn([unwantedValue1, unwantedValue2])));
If that doesn't do quite what you want, you also can use the predicate
to easily create your own Matcher
from a boolean function.
(You might not have found these if you were searching the Mockito documentation
because they're part of package:matcher
(normally included as part of package:test
); they're used for unit tests in general, not just for mocks.)
Saran
Updated on January 03, 2023Comments
-
Saran over 1 year
To set the context, I am trying to do this in Flutter.
For example,
I have a test that passes, "if I set my mock to say 'no network connection' and expect 'NetworkUnavailable' to result."
Then, I thought to write next test that "if network is available, result could be anything except 'NetworkUnavailable'"
I am struggling to setup an expect matcher for that. Does Mockito has something for this, something like
AnyExcept([matcher])
?Thanks.
-
Saran about 2 yearsPerfect. Thanks.