-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Help: Flutter Bloc Test: Unexpected State Change After Multiple Events #4044
Comments
Hello @dipu0 can you share the |
|
Hello @dipu0, is very hard to debug without syntax highlighting or running the code. But from a quick overview, I think something that could simplify your test is instead of adding the You can use the
Doing this will help you isolate the test scenario and analyze what is going on. |
Already tried to use seed, but same!!!
If I set the status to CallbackStatus.loading and itemCartCount: 2, it produces an error. If I set it to 1, the test case passes.
Here, and also in the previous test, the main problem was in the response (ItemEntity List). In the state, I have three things: CallbackStatus, a response which is a list of ItemEntity, and total. In every stage callback and total are correctly emitted, but in the response list, cartItemCount should start with 2 while CallbackStatus is loading and decrease by 1 in the last emit. However, cartItemCount stays the same as the last emit from the initial emits. |
@dipu0 In that case, this is an issue probably with your implementation, as I said is very hard to analyze or debug with just the code snippets, can you please share a link to a minimal reproduction sample on GitHub or DartPad? It would be much easier to help if I can reproduce the issue locally, thanks! |
Closing for now since there aren't any actionable next steps without a link to a minimal reproduction sample. If this is still an issue please provide a link to a minimal reproduction sample on either GitHub or DartPad and I'm happy to take a closer look, thanks! |
I'm currently facing an issue with Flutter Bloc testing where I have a sequence of events: fetching items, then decrementing the item count. The problem is that the expected state after the decrement is not matching the actual state. It seems like the item count is being decremented from the initial state instead of the state after fetching the items.
In my case, I have a single state class which uses copyWith function. In state response list remains same from GetCartItem to decrement in the bloc.stream getting data. When I call two events one after another, like 'get items' event then than 'decremented count'.
Here's the relevant code snippet:
Error shows
The issue is that the actual state after the second event shows the item count decremented from the initial state, but it should be from the state after fetching items.
I would appreciate any insights or suggestions on how to resolve this issue. Thanks in advance!
The text was updated successfully, but these errors were encountered: