我正在开发一个使用 WeatherAPI 的应用程序。我目前无法实施一些工作测试。我尝试遵循 ResoCoders 指南(https://resocoder.com/2019/11/29/bloc-test-tutorial-easier-way-to-test-blocs-in-dart-flutter/)并实际实现了所有状态,块(我用 Cubit 代替)、类、函数……几乎相同。
这是我的测试代码:
blocTest<WeatherCubit, WeatherBaseState>(
'Cubit emits WeatherLoaded',
build: () {
return WeatherCubit(weatherRepository: mockWeatherRepository);
},
act: (WeatherCubit cubit) => cubit.getWeather(),
expect: () => [
WeatherLoaded(
temperature: temperature,
...
lat: lat,
lon: lon)
],
);
Run Code Online (Sandbox Code Playgroud)
这是我从调试控制台得到的错误信息:
Expected: [Instance of 'WeatherLoaded']
Actual: [Instance of 'WeatherLoaded']
Which: at location [0] is <Instance of 'WeatherLoaded'> instead of <Instance of 'WeatherLoaded'>
WARNING: Please ensure state instances extend Equatable, override == and hashCode, or implement Comparable.
Alternatively, consider using …Run Code Online (Sandbox Code Playgroud)