【发布时间】: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