Questions tagged [bloc-test]
31 questions
7
votes
1 answer
Bloc test with Flutter, wait for async action
I have this bloc_test in my Flutter code
blocTest(
'emits [ProjectsState.loading(), ProjectsState.succes([])] with empty projects',
build: () => projectsBloc,
act: (bloc) => bloc.add(const…

Rob van Putten
- 349
- 1
- 5
5
votes
1 answer
Bad state: A test tried to use any or captureAny on a parameter of type T State using bloc_test and mocktail
I tried the solutions in here https://github.com/felangel/mocktail/issues/42 but still get error.
This is my code:
class MockUserRepository extends Mock implements UserRepository {}
class MockAuthenticationBloc extends MockBloc

noyruto88
- 767
- 2
- 18
- 40
5
votes
1 answer
How to implement widget tests by using MockBloc?
I'm trying to implement a Widget Test in order to test a login form. This test depends on a bloc which I'm mocking by using MockBloc. However, it throws the following error:
══╡ EXCEPTION CAUGHT BY FLUTTER TEST…

Yunet Luis Ruíz
- 425
- 4
- 16
4
votes
2 answers
Dart / Flutter test cubit, problem with comparing expected and actual
I'm working on an app using a WeatherAPI. I currently fail to implement some working tests. I tried to follow ResoCoders Guide (https://resocoder.com/2019/11/29/bloc-test-tutorial-easier-way-to-test-blocs-in-dart-flutter/) and actually implemented…

CoffeeToCodette
- 43
- 1
- 8
3
votes
2 answers
bloc_test: Bad state: Cannot emit new states after calling close
I have a problem in Test section of flutter, I wrote a test for simple counter app which uses cubit, but while I run all test it gives me the error mentioned in header, any body knows why?
it is necessary to say that while I run the tests one by one…

Jafar ashrafi
- 511
- 6
- 18
2
votes
1 answer
Flutter bloc test with droppable event
How can I test a bloc event using flutter bloc test that has a droppable (or restartable) event?
Event example:
on(
_mapSomeEvent,
transformer: droppable(),
);
I tried calling events right after the droppable event inside a flutter…

Ianmcuki
- 21
- 1
2
votes
1 answer
Flutter: bloc test problem with comparing expected and actual
I have tests like the below:
blocTest(
'emits [ViewData.loading and ViewData.loaded] when GetRepositories is added',
build: () {
when(
() => useCase.getRepositories(),
).thenAnswer((_) async =>…

R Rifa Fauzi Komara
- 1,915
- 6
- 27
- 54
2
votes
1 answer
How to do Unit Testing on bloc using blocTest?
I have a bloc that works to get cartItem from orderItem by id and i want to test the bloc, I've read some bloc testing from flutter_bloc but I still don't know how to implement it on my bloc. I want to do a test using dummy data that I made. I want…

Raka Prasetyo
- 57
- 1
- 6
2
votes
1 answer
Flutter test bloc error type 'Null' is not a subtype of type
I'm testing a bloc method that fetch a list of restaurants fro the api.
here is my code :
import 'package:bloc_test/bloc_test.dart';
import 'package:flutter_test/flutter_test.dart';
import…

karmous
- 197
- 3
- 12
2
votes
0 answers
Flutter BLoC Test failures
Currently trying to implement Unit testing for my cubit and am feeling there is a severe lack in documentation for BLoC test online or useful examples. Can anyone explain what I'm doing wrong with setting up this test. I can't seem to figure out…

DA_cloak
- 21
- 5
2
votes
1 answer
Flutter Bloc Test : Null check operator used on a null value (null-safety)
I am using flutter_bloc, bloc_test, and bloc_testing to implement testing. But even after I initialize Bloc in Setup the errors say Null check operator used on a null value.
import 'package:bloc_test/bloc_test.dart';
import…

Raj Dhakad
- 852
- 2
- 17
- 39
1
vote
1 answer
BloC testing "The method xxx isn't defined for the type 'Object'" error
I am trying to learn testing with bloc. Followed the procedure as stated in docs.
I have lib/cubit/counter_cubit.dart and lib/cubit/counterState.dart files
counter_cubit.dart is:
import 'package:bloc/bloc.dart';
import…
user17297758
1
vote
1 answer
bloc test output unexpected result
I'm confused by the results of the test below
the first doesn't pass,
but somehow the second does not
what am I missing?
thank you
void main() {
group('UserAuthenticationCubit', () {
const user = User(name: 'name', id: 'id');
final repo…

aoatmon
- 507
- 4
- 13
1
vote
2 answers
Flutter: How can I unit test a Timer used by a Bloc using blocTest?
How can I test a Timer inside a Bloc, using blocTest?
I’m using the bloc library, with freezed to build the state and event objects (might not matter here, but who knows).
So let’s say I have something like this in my bloc…

michpohl
- 852
- 8
- 30
1
vote
1 answer
how do you test a flutter block that consumes a stream
i have a bloc that listens to a stream for authentication events (listening for firebase user events). my block is;
class AuthenticationBloc
extends Bloc {
…

socrates hlapolosa
- 21
- 5