Cubit の単体テストを設定しようとしていますが、ブロック テストに問題があるようです。値の初期状態を確認しようとするだけで、通常のテストでは問題なく動作しますが、ブロック テストで同じことを試みるとすぐに、[0] の実際の空のリストで失敗し、よくわかりません。私が間違っていること。このエラーに役立つインターネット上の情報はありません。
//passes
test('initial state of SettingsCubit', () {
expect(
settingsCubit.state,
SettingsState(
notificationsEnabled: false,
gpsEnabled: false,
celsiusEnabled: false,
expandNavigation: false,
breakingNewsNotifications: false,
trendingNotifications: false,
liveRemindersNotifications: false,
sportsNotifications: false));
});
//fails
blocTest(
'initial state of SettingsCubit',
build: () => SettingsCubit(),
expect: () => [
SettingsState(
expandNavigation: false,
gpsEnabled: false,
celsiusEnabled: false,
notificationsEnabled: false,
breakingNewsNotifications: false,
trendingNotifications: false,
liveRemindersNotifications: false,
sportsNotifications: false,
)
],
);
エラー:
package:bloc_test/src/bloc_test.dart 193:9 testBloc.<fn>
===== asynchronous gap ===========================
dart:async _asyncThenWrapperHelper
package:bloc_test/src/bloc_test.dart testBloc.<fn>
dart:async runZonedGuarded
package:bloc_test/src/bloc_test.dart 172:9 testBloc
package:bloc_test/src/bloc_test.dart 140:11 blocTest.<fn>
package:bloc_test/src/bloc_test.dart 139:26 blocTest.<fn>
Expected: [
SettingsState:SettingsState(expandNavigation: false, gpsEnabled: false, celsiusEnabled: false, notificationsEnabled: false,breakingNewsNotifications: false, trendingNotifications: false, liveRemindersNotifications: false, sportsNotifications: false)
]
Actual: []
Which: at location [0] is [] which shorter than expected
SettingsCubit と SettingsState コードは次の場所にあります: Flutter BLoC テストの失敗