Вот объект de для сравнения MapState
:
class MapState {
final Coordinate currentCoordinate;
final Iterable<Coordinate> markers;
MapState(this.currentCoordinate, this.markers);
MapState.empty()
: this.currentCoordinate = null,
this.markers = [];
MapState.withCoordinate(this.currentCoordinate) : this.markers = [];
MapState.withMarkers(this.markers) : this.currentCoordinate = null;
MapState newCoordinate(final Coordinate coordinate) =>
MapState(coordinate, this.markers);
MapState newMarkersSet(final Iterable<Coordinate> markers) =>
MapState(this.currentCoordinate, markers);
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is MapState &&
runtimeType == other.runtimeType &&
currentCoordinate == other.currentCoordinate &&
markers == other.markers;
@override
int get hashCode =>
currentCoordinate.hashCode ^
markers.hashCode;
}
Вот модульный тест:
test('init, Observer should receive an empty state as a first state',
() {
expect(MapState.empty(), MapState.empty());
});
Результат (конечно, неудача):
Ожидается: экземпляр MapState
Фактически: экземпляр MapState
пакет: test_api ожидают
пакет: flutter_test / src / widget_tester.dart 196: 3 ожидают
test / application / map_bloc_test.dart 25: 5 main.
Я упростил первичный тест до этого, чтобы отследить ошибку, так что не смущайтесь бессмысленным юнит-тестом.
Изменение expect(MapState.empty(), MapState.empty());
на expect(1, 1);
помогает, но я не могу заставить его работать с моими объектами.
Кроме того, вот мой блок импорта:
import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:taxi/application/map_bloc.dart';
import 'package:taxi/domain/map.dart';
P.S .: как ни странно, но изменение this.markers = []
на this.markers = const []
помогает. Wut ??? Во всяком случае, expect([], []);
работает. Это просто не имеет никакого смысла для меня.