所以我要对一个单元进行单元测试
我的测试很简单
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'>
所以它说它发出了初始状态,但不是吗?
答案 0 :(得分:-1)
我们遇到了同样的错误。它是通过使用 equatable 修复的。