Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Status
IN DEVELOPMENT
Breaking Changes
NO
Description
(This pull request changes only bloc_test.dart in bloc_test package)
Testing a bloc with a complex state, can be an heavy burden, expecially when:
The proposal:
This kind of test is valid when a sequential transformer is used. I added a saga parameter to bloc_test, so a series of steps can be passed, one step can have an action or an event to the bloc, and a list of predicates to check the state changes resulting from that action/event, for example:
If the number of state transition is lesser than the predicates specified, the test fails.
'Step class:
Defines a step of the saga tha we want to test
act
is an optional callback which will be invoked tho use methods of the with the bloc under test. In case of adding events to a bloc it's simplier to usehappens
, to which an event instance can be passed.act
andhappens
are mutually exclusive but both are optional, aStep
can be used to only check a state.outputs
is a list of callbacks (bool Function(S value)
). For every callback a state is popped out, if the callback result is false the test fails.description
A description for the Step, it will output in message, in case of failurewait
the time to wait prior to check every outputtimeOut
the maximum time to wait for states output from the blocAll original test are working, so it seems that no regression are introduced. New test are also promising, because the original tests rewritten in this new form are passing without any problem.
TODO:
I made this change to test a bloc that I'm building, designing the saga steps before writing event handlers in a sort-of TDD, I find it very useful, so I would share it. Please feel free to give me any feedback, there is alway space to learn, and any kind of comment will be appreciated.
Thank you for your work,
Type of Change