ProviderContainer.test constructor

  1. @visibleForTesting
ProviderContainer.test({
  1. ProviderContainer? parent,
  2. List<Override> overrides = const [],
  3. List<ProviderObserver>? observers,
  4. Retry? retry,
})

An automatically disposed ProviderContainer.

This also adds an internal check at the end of tests that verifies that all containers were disposed.

This constructor works only inside tests, by relying on package:test's addTearDown.

Implementation

@visibleForTesting
factory ProviderContainer.test({
  ProviderContainer? parent,
  List<Override> overrides = const [],
  List<ProviderObserver>? observers,
  Retry? retry,
}) {
  final container = ProviderContainer(
    parent: parent,
    overrides: overrides,
    observers: observers,
    retry: retry,
  );
  test.addTearDown(container.dispose);

  return container;
}