我有以下设置:
class Resource<T> {
T? data;
String? error;
Resource._({this.data, this.error});
factory Resource.success(T? data) => Resource._(data: data);
factory Resource.error(String error) => Resource._(error: error);
factory Resource.loading() => Resource._();
}
class CategoriesRepo{
Stream<Resource<List<Category>>> getAllCategories() async* {
yield Resource.loading();
yield (Resource.error(NetworkErrors.NO_INTERNET));
}
}
test('Loading then error',
() async {
final categoriesRepo = CategoriesRepo();
expect(
categoriesRepo.getAllCategories(),
emitsInOrder([
Resource<List<Category>>.loading(),
Resource<List<Category>>.error(""),
]));
});
我收到此错误:
test\unit-tests\screens\categories\categories_repo_test_test.dart main.<fn>.<fn>
Expected: should emit an event that <Instance of 'Resource<List<Category>>'>
Actual: <Instance of '_ControllerStream<Resource<List<Category>>>'>
Which: emitted * Instance of 'Resource<List<Category>>'
* Instance of 'Resource<List<Category>>'
x Stream closed.
如何正确测试上述流?