Skip to content

Proposal: Do not mock microtasks by default #2309

@rrousselGit

Description

@rrousselGit

I think that while the ability to mock microtasks can be useful, most use-cases don't really care about this. Instead, people likely use fake_async for Duration based APIs like clocks or timers

By not mocking microtasks, this could allow writing things like:

await fakeAsync((async) async {
  // random example showing how we can mix elapse and async/await
  final repository = Repository(cacheTime: Duration(seconds: 5));
  repository.cache = {'value': 42};

  final response = await fetchSomething(repository); // would otherwise block if microtasks were mocked
  expect(response.value, 42);

  async.elapse(Duration(seconds: 5));

  expect(repository.cache, null);
});

Unless I'm missing something important and mocking microtasks is necessary for proper Timer mock, I think this behavior would be more intuitive for users.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions