Skip to content

Add expectLater to flutter_test - #17063

Merged
tvolkert merged 2 commits into
flutter:masterfrom
tvolkert:expectlater
Apr 28, 2018
Merged

tvolkert merged 2 commits into
flutter:masterfrom
tvolkert:expectlater

Conversation

@tvolkert

Copy link
Copy Markdown
Contributor
  • Wrap expectLater() in flutter_tester so that callers can
    wait for the matcher to complete in their tests

#16859

* Wrap `expectLater()` in flutter_tester so that callers can
  wait for the matcher to complete in their tests

#16859
@tvolkert
tvolkert requested a review from Hixie April 27, 2018 23:33
@@ -158,6 +158,19 @@ void expectSync(dynamic actual, dynamic matcher, {
test_package.expect(actual, matcher, reason: reason);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention expectLater in expect's documentation.
Have expect assert that it didn't get a Future back, and if it did, fail with a message saying that you either have a bug or you should consider expectLater.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect can't get a future back, because it calls test_package.expect(), which returns void.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, that's quite unfortunate.

/// has finished matching.
///
/// If the matcher fails asynchronously, that failure is piped to the returned
/// future where it can be handled by user code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain what happens if it isn't handled by user code (presumably the test fails?)

String reason,
dynamic skip, // true or a String
}) {
TestAsyncUtils.guardSync();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be wrapped in a guard, rather than just being a synchronous guard? Or is it ok if expectLater isn't awaited?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out this does need to just be guardSync(). Otherwise, we run into other async barriers while we're waiting for the matcher to complete. e.g.:

asyncBarrier(); // When using AutomatedTestWidgetsFlutterBinding, this flushes the microtasks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sent #17085 to fix this.

@Hixie

Hixie commented Apr 28, 2018

Copy link
Copy Markdown
Contributor

tests?

@tvolkert

Copy link
Copy Markdown
Contributor Author

tests?

I can't test this without #17029, or the test will timeout 😛

@tvolkert

Copy link
Copy Markdown
Contributor Author

tests?

I can't test this without #17029, or the test will timeout

Actually, I can use package:test directly to test - update coming...

@tvolkert

Copy link
Copy Markdown
Contributor Author

Tests added

@tvolkert

Copy link
Copy Markdown
Contributor Author

Merging on red because of a suspected flake.

@tvolkert
tvolkert merged commit 8b99d1d into flutter:master Apr 28, 2018
@tvolkert
tvolkert deleted the expectlater branch April 28, 2018 21:03
tvolkert added a commit that referenced this pull request Apr 30, 2018
DaveShuckerow pushed a commit to DaveShuckerow/flutter that referenced this pull request May 14, 2018
* Wrap `expectLater()` in flutter_tester so that callers can
  wait for the matcher to complete in their tests

flutter#16859
DaveShuckerow pushed a commit to DaveShuckerow/flutter that referenced this pull request May 14, 2018
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants