Bloc: [Test] Question: is blocTest always emit first state even first state equals initial state?

Created on 14 Oct 2020  路  3Comments  路  Source: felangel/bloc

Question

Is blocTest will always emit the state even the first state equals the initial state?

I notice there is a breaking change, is this a side-effect of it?

    blocTest<SomeBloc, SomeState>(
      'when the first state is equal to initial state',
      build: () => SomeBloc(),
      act: (bloc) async {
        // the event just do: yield state
        bloc.add(const SomeEvent.doSomething());
      },
      // in the previous version, should be expect:[] with skip: 1,
      expect: [
        SomeState.initial(),
      ],
      skip: 0,
    );
question

Most helpful comment

Hi @Peng-Qian 馃憢
Thanks for opening an issue!

That was an intentional change made to allow blocs to "reignite" (re-notify) listeners if needed when they are created. This is working as expected and if you'd like you can just skip it 馃憤

Hope that helps!

All 3 comments

Hi @Peng-Qian 馃憢
Thanks for opening an issue!

That was an intentional change made to allow blocs to "reignite" (re-notify) listeners if needed when they are created. This is working as expected and if you'd like you can just skip it 馃憤

Hope that helps!

Thx for your quick reply!

Oh, that's why! I spent too much time finding out why when testing Bottom Navigation Bar when the initial index is 0. When I changed to the same index, [0] was emitted (I thought it should be empty). But when doing it after switching to 1st index and then two times 0 index - then actual was [1, 0] - so 0 index was emitted only once. Glad I found this 馃槂

Was this page helpful?
0 / 5 - 0 ratings