-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try subclasses while faking sealed
classes
#675
Comments
Yes, that would be nice and I already had this improvement in my head. But that's a low priority for us currently. Contributions are welcome. The idea how to implement this would be quite simple: during code generation, if we have to create a fake of the |
sealed
classes
Thought a bit more about it. I think that's totally fine and will be an actual improvement, to pass a fake of a child class as I wouldn't pass the same fake value as |
Any work around for this yet? |
I don't have any timeline for version 6 though. |
Thanks @yanok |
@yanok can you maybe provide some more details on the decision process? I think it's a big decision to not support a newly added core feature of the Dart language. |
@martin-formigas Well, sealed classes are mutually incompatible with mocks, so we don't have much choice. Consider that you have sealed class Pet {}
class Cat extends Pet {}
class Dog extends Pet {}
void speak(Pet pet) => switch (pet) {
Cat() => print('Meow'),
Dog() => print('Woof')
// Note that you don't need a "catch all" clause here, since Dart can see you exhausted all the possibilities.
} Now imagine you managed to create a You can mock |
@martin-formigas so the decision process was actually on the language side: the language team wanted to get exhaustiveness for sealed classes (which is generally good), they did realize that it will break mocking and they decided exhaustiveness is more important. We just have to follow here. If you want my personal opinion, I'd do the same, but I wasn't involved in the process. |
Got it, thanks for the insight! I think this issue can be closed then, since there will never be an actual resolution? |
There are two separate issues with sealed classes:
|
Hi @yanok I ran into one problem that if I have a
|
You might be able to drop the |
Thanks @yanok but that's not what I mean. I will inspect about this and get back to you later |
I have some trouble when using sealed class.
This is a sample :
I have this error
`This means Mockito was not smart enough to generate a dummy value of type
'Pet'. Please consider using either 'provideDummy' or 'provideDummyBuilder'
functions to give Mockito a proper dummy value.
Please note that due to implementation details Mockito sometimes needs users
to provide dummy values for some types, even if they plan to explicitly stub
all the called methods.`
I have to add
provideDummy(cat);
beforewhen
.If i do this it works.
It would be nice if sealed class was compatible without provide dummy value !
The text was updated successfully, but these errors were encountered: