Add option to override whole provider/argprovider#40
Add option to override whole provider/argprovider#40manuel-plavsic wants to merge 1 commit intomainfrom
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #40 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 10 10
Lines 288 288
=========================================
Hits 288 288
🚀 New features to boost your workflow:
|
|
Technically, we could easily add two wrapper types |
|
@manuel-plavsic If you remove overrideWithValue it's going to be a breaking change and we have to bump a major. Additionally, what do you think about numberProvider.overrideWith(mockNumberProvider),
// instead of
numberProvider.overrideWithProvider(mockNumberProvider),? |
|
@nank1ro good idea, I'll rename the method to |
|
and yes, it makes sense to keep |
This PR attempts to solve #35.
Tl;dr: I propose to remove
overrideWithValuein favour ofoverrideWithProvider. For example, instead of:one should write
Explanation: this second variant can do everything the first variant can do. It is just more powerful, as also
lazy, a propercreateanddisposecan be specified.This is even more useful when working with argument providers, whose mocking functionality is currently not ideal IMO. At the moment, one can only override the whole argument provider, but cannot make argument distinctions. This defeats the point of argument providers. Here is how it currently is on
main:disco/packages/disco/test/disco_test.dart
Lines 728 to 753 in 738b1ea
So, we definitely need arguments. In my current implementation, they would work like this:
However, I don't think this approach is ideal. People will have to write some custom logic somewhere every time they want to use the override (because they need to use specific arguments and provide specific values for that).
We should purse this approach instead:
This way, one can just write the custom logic in
mockNumberProvider'screateanddispose, without polluting the widget tree. This is also what was asked in the linked issue.The logic for this would still have to be adapted in
ProviderScope. Before I invest time there, is this okay for you @nank1ro?Right now, I added sealed classes and pattern matching to allow both
overrideWithValueandoverrideWithProvider, but if we get rid of the former, we don't need the sealed classes and pattern matching anymore.