所以,我使用了这个 bloc_test 库版本bloc_test: ^5.0.0
。以前我用这段代码测试 bloc 并且工作正常
test(
'should emit [RegisterLoadingState,RegisterLoadedState] when RegisterWithPassword is successful',
() async {
setUpSuccessfulValidateRegister();
setUpSuccessfulRegister();
final expected = [
RegisterInitialState(),
RegisterLoadingState(),
RegisterLoadedState(account: customer),
];
expectLater(bloc, emitsInOrder(expected));
bloc.add(RegisterWithPasswordEvent(
name: nameTest,
email: emailTest,
password: passwordTest,
retypedPassword: retypedPasswordTest,
));
});
目前我使用 bloc_test 包更改它并且测试失败
blocTest(
'should emit [RegisterLoadingState,RegisterLoadedState] when RegisterWithPassword is successful',
build: () async {
setUpSuccessfulValidateRegister();
setUpSuccessfulRegister();
return bloc;
},
act: (bloc) => bloc.add(RegisterWithPasswordEvent(
name: nameTest,
email: emailTest,
password: passwordTest,
retypedPassword: retypedPasswordTest,
)),
expect: [
RegisterLoadingState(),
RegisterLoadedState(account: customer),
],
);
这是测试中的错误
Expected: [
RegisterLoadingState:RegisterLoadingState,
RegisterLoadedState:RegisterLoadedState
]
Actual: [
RegisterLoadingState:RegisterLoadingState,
RegisterLoadedState:RegisterLoadedState
]
Which: was RegisterLoadedState:<RegisterLoadedState> instead of RegisterLoadedState:<RegisterLoadedState> at location [1]
package:test_api expect
package:bloc_test/src/bloc_test.dart 124:25 blocTest.<fn>
account
如果我用参数删除了状态中的等价表,错误就消失了。任何人都知道为什么这个测试适用于第一个代码并且使用 bloc_test 包失败?