Flutter bloc emmitInOrder 不会发出初始状态,但会发出

Cas*_*iel 8 flutter flutter-test

所以我正在尝试对一个块进行单元测试

我的测试很简单

test("When loading patients, bloc should emmit [Loading], [OwnersLoaded]", (){
      //arrange
      var owners = [Owner(id: "TestId")];
      when (mockPatientsRepository.getOwnersForCurrentPractice()).thenAnswer((_)=>Future.value(owners));
      final List<PatientsState> expected = [patientsBloc.initialState, Loading(), OwnersLoaded(owners)];

      //assert later
      expectLater(patientsBloc, emitsInOrder(expected));

      //act
      useCase.getPatients();
    }); 
Run Code Online (Sandbox Code Playgroud)

所有者确实覆盖了等于和哈希

我的错误信息

Expected: should do the following in order:
          • emit an event that <Instance of 'InitialPatientsState'>
          • emit an event that <Instance of 'Loading'>
          • emit an event that <Instance of 'OwnersLoaded'>
  Actual: <Instance of 'PatientsBloc'>
   Which: emitted • Instance of 'InitialPatientsState'
                  • Instance of 'Loading'
                  • Instance of 'OwnersLoaded'
            which didn't emit an event that <Instance of 'InitialPatientsState'> 
Run Code Online (Sandbox Code Playgroud)

所以它说它发出了初始状态,但没有发出?

小智 0

我们有同样的错误。它是通过使用 equalable 修复的。