【问题标题】:Flutter bloc emmitInOrder doesn't emit initial state, but it doesFlutter bloc emmitInOrder 不会发出初始状态,但会发出
【发布时间】:2020-02-21 06:57:25
【问题描述】:

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

我的测试很简单

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();
    }); 

所有者确实会覆盖等号和哈希

我的错误信息

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'> 

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

【问题讨论】:

  • 你能把你的块的代码也放上来吗?
  • 你是如何解决这个错误的?
  • @Hunt 如果事件“相等”,则它们不会被重新发出。我已经开始使用冷冻机来获得集团内的价值平等

标签: flutter flutter-test


【解决方案1】:

我们遇到了同样的错误。它已通过使用 equatable 修复。

【讨论】:

猜你喜欢
  • 2021-02-10
  • 2022-01-21
  • 2020-12-09
  • 2022-10-06
  • 2021-10-22
  • 2021-03-10
  • 2021-01-07
  • 2020-12-01
  • 2021-02-22
相关资源
最近更新 更多