Skip to content
module_test โ€บ Functions โ€บ testModule<T extends dynamic> function

testModule<T extends dynamic> โ€‹

Future<void> testModule<T extends dynamic>(T module, FutureOr<void> Function(T module, TestBinder binder) body, {(void Function(dynamic))? overrides, dynamic overrideScope})

Test helper that initializes a Module in isolation, runs the body callback, and disposes the controller afterward.

Creates a SimpleBinder wrapped in a TestBinder, initializes the module's full lifecycle (binds, imports, exports), and passes both the module instance and the test binder to the callback for assertions.

Optionally accepts overrides and overrideScope to test DI overrides.

Example โ€‹

dart
await testModule(
  MyModule(),
  (module, binder) async {
    expect(binder.get<MyService>(), isNotNull);
    expect(binder.hasSingleton<MyService>(), isTrue);
  },
);

See also:

  • TestBinder for inspecting registration and resolution history.