Pruebas

Most test scenarios map directly a ProviderContainer APIs: read, invalidate, refresh, listen, y overrides per provider instance.

Test Strategy

Split tests into pure container tests y widget integration tests.

Pure Dart

Use ProviderContainer directly para read/invalidate/refresh assertions

Overrides

Override per provider instance con overrideWith / overrideWithValue

Widget tests

Inject external container y dispose it explicitly

Tip

ProviderContainer.listen does not emit initial value unless fireImmediately: true is specified.

Test Command y Lista de verificaci?n

Run full suite y verify no pending timer leaks en autoDispose scenarios.

Command

flutter test

Checklist

- Dispose externally injected ProviderContainer in tearDown.
- Use fireImmediately: true when your listener assertions need initial state.
- For autoDispose tests, advance fake time beyond autoDisposeDelay.

ejemplo: per-argument override

family-like providers are overridden per instance created de your factory function.

product_provider_test.dart
class ProductById extends Provider<Product> {
  ProductById(this.id) : super.args((id,));
  final String id;

  @override
  Product build(ref) {
    final repo = ref.watch(productRepoProvider);
    return repo.fetch(id);
  }
}

final container = ProviderContainer(
  overrides: [
    productByIdProvider('a').overrideWithValue(const Product(id: 'a', name: 'stub')),
  ],
);

// assert and cleanup
container.dispose();
This pattern mirrors the README y upstream tests en miniriverpod repository.
Widget tests should unmount widgets before disposing external containers.
Use fake_async a validate autoDispose delays y keepAlive behavior.

Siguientes pasos

API Referencia

Open quick signatures para ProviderContainer, Ref, AsyncValue, y mutation APIs.

Open API Referencia

Back a resumen

Return a the full documentation map para miniriverpod.

Open resumen