Skip to content

Commit

Permalink
Tighten types in test utils (#2097)
Browse files Browse the repository at this point in the history
Towards #2095

Use `Queue.of` to infer the collection type from the argument instead of
`Queue.from` which ignores the argument type.

Expand a bare `Function` to a full signature function type.
  • Loading branch information
natebosch committed Sep 25, 2023
1 parent 9d99791 commit d3f4b36
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
7 changes: 4 additions & 3 deletions pkgs/test/test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ State? lastState;
///
/// The most recent emitted state is stored in [_lastState].
void expectStates(LiveTest liveTest, Iterable<State> statesIter) {
var states = Queue.from(statesIter);
var states = Queue.of(statesIter);
liveTest.onStateChange.listen(expectAsync1((state) {
lastState = state;
expect(state, equals(states.removeFirst()));
Expand All @@ -50,8 +50,9 @@ void expectStates(LiveTest liveTest, Iterable<State> statesIter) {

/// Asserts that errors will be emitted via [liveTest.onError] that match
/// [validators], in order.
void expectErrors(LiveTest liveTest, Iterable<Function> validatorsIter) {
var validators = Queue.from(validatorsIter);
void expectErrors(
LiveTest liveTest, Iterable<void Function(Object)> validatorsIter) {
var validators = Queue.of(validatorsIter);
liveTest.onError.listen(expectAsync1((error) {
validators.removeFirst()(error.error);
}, count: validators.length, max: validators.length));
Expand Down
2 changes: 2 additions & 0 deletions pkgs/test_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 0.6.2-wip

## 0.6.1

* Drop support for null unsafe Dart, bump SDK constraint to `3.0.0`.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/test_api/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: test_api
version: 0.6.1
version: 0.6.2-wip
description: >-
The user facing API for structuring Dart tests and checking expectations.
repository: https://github.com/dart-lang/test/tree/master/pkgs/test_api
Expand Down
7 changes: 4 additions & 3 deletions pkgs/test_api/test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ State? lastState;
///
/// The most recent emitted state is stored in [_lastState].
void expectStates(LiveTest liveTest, Iterable<State> statesIter) {
var states = Queue.from(statesIter);
var states = Queue.of(statesIter);
liveTest.onStateChange.listen(expectAsync1((state) {
lastState = state;
expect(state, equals(states.removeFirst()));
Expand All @@ -36,8 +36,9 @@ void expectStates(LiveTest liveTest, Iterable<State> statesIter) {

/// Asserts that errors will be emitted via [liveTest.onError] that match
/// [validators], in order.
void expectErrors(LiveTest liveTest, Iterable<Function> validatorsIter) {
var validators = Queue.from(validatorsIter);
void expectErrors(
LiveTest liveTest, Iterable<void Function(Object)> validatorsIter) {
var validators = Queue.of(validatorsIter);
liveTest.onError.listen(expectAsync1((error) {
validators.removeFirst()(error.error);
}, count: validators.length, max: validators.length));
Expand Down

0 comments on commit d3f4b36

Please sign in to comment.