Bloc: Mock a bloc for unit tests

Created on 16 Jul 2019  路  2Comments  路  Source: felangel/bloc

Hi

It is there a way to create a mock of a bloc for unit tests? I tried to create a mock but its current state is null.

Thank you in advance

question

Most helpful comment

thank you!
It works perfect!

All 2 comments

Hi @jkyon 馃憢
Thanks for opening an issue!

Regarding your question you can create a mock bloc using mockito like so:

class MockBlocA extends Mock implements BlocA {}

you can then create an instance like so

void main() {
  group('Tests', () {
    BlocA blocA;

    setUp(() {
        blocA = MockBlocA();
    });
  });
}

Then you can mock the currentState in your tests like so:

when(blocA.currentState).thenAnswer((_) => BlocAState());

Hope that helps and great question! 馃憤

thank you!
It works perfect!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timtraversy picture timtraversy  路  3Comments

shawnchan2014 picture shawnchan2014  路  3Comments

zjjt picture zjjt  路  3Comments

Reidond picture Reidond  路  3Comments

clicksocial picture clicksocial  路  3Comments