Skip to content
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

proposal: adding stubs #1

Open
erickzanardo opened this issue Feb 2, 2022 · 5 comments
Open

proposal: adding stubs #1

erickzanardo opened this issue Feb 2, 2022 · 5 comments

Comments

@erickzanardo
Copy link

Hey,

I have a proposal that was originally sent on the mocktail repo, but after some discussion we decided that it would be better fitted on an external package.

Would this be something that you would be open to be added to this package?

If so I would love to work on a PR adding it.

@shinayser
Copy link
Owner

shinayser commented Feb 2, 2022

OLHA O ERICK AÍ, hahaha!!! E aí mano, beleza? Quanto tempo! 😊

Hey Erick! Correct me if I am wrong: you are propossing to add some classes that provide default implementations, right? Or you want to add some high-order objects (maybe const?) that already provide the implementations for us?

@erickzanardo
Copy link
Author

erickzanardo commented Feb 2, 2022

Opa beleza e por ai? :D

The idea is to add some default Stub classes, which are simple mocks that allows us easily check if callbacks were called. In this collection we would have some common cases like VoidStub, StringStub, IntStub, etc.

That way if someone wants to test if a GestureDetector worked for example, they could do something like this:

final stub = VoidStub();
await tester.pumpWidget(GestureDetector(onPressed: stub.onCall, child: Text('tap me'));
await tester.tap(find.text('tap me'));

verify(stub.onCall).called(1);

@shinayser
Copy link
Owner

shinayser commented Feb 2, 2022

Sounds really cool to me! But I wonder if we can go further and also provide some default implementations with some high order const variables, like:

const kVoidStub = VoidStub();
const kStringStub = StringSubt();
const kIntStub = IntStub();

Does it make sense?

@erickzanardo
Copy link
Author

Mock doesn't have a const constructor iirc. But even if it does I don't believe that could be add much value, if we provide default instances, then that instance would be "dirty" among tests, for mocks it is better that the user create an instance per test and I don't think we should influence the user on the other direction, wdyt?

@shinayser
Copy link
Owner

Oh I see. Anyway, feel free to open the PR and I will be glad to approve it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants