- override
Call the testBody inside a FakeAsync scope on which pump can
advance time.
Returns a future which completes when the test has run.
Called by the testWidgets and benchmarkWidgets functions to
run a test.
The invariantTester argument is called after the testBody's Future
completes. If it throws, then the test is marked as failed.
Source
@override
Future<Null> runTest(Future<Null> testBody(), VoidCallback invariantTester) {
assert(!inTest);
assert(_fakeAsync == null);
assert(_clock == null);
_fakeAsync = new FakeAsync();
_clock = _fakeAsync.getClock(new DateTime.utc(2015, 1, 1));
Future<Null> testBodyResult;
_fakeAsync.run((FakeAsync fakeAsync) {
assert(fakeAsync == _fakeAsync);
testBodyResult = _runTest(testBody, invariantTester);
assert(inTest);
});
// testBodyResult is a Future that was created in the Zone of the fakeAsync.
// This means that if we call .then() on it (as the test framework is about to),
// it will register a microtask to handle the future _in the fake async zone_.
// To avoid this, we wrap it in a Future that we've created _outside_ the fake
// async zone.
return new Future<Null>.value(testBodyResult);
}