mockLazy<T> method

ZenTestMode mockLazy<T>(
  1. T factory(), {
  2. String? tag,
  3. bool alwaysNew = false,
})

Replace a dependency with a factory function

Useful when you need to create a new instance for each test. By default, creates a singleton on first access. Set alwaysNew to true to create fresh instance each time.

Implementation

ZenTestMode mockLazy<T>(
  T Function() factory, {
  String? tag,
  bool alwaysNew = false,
}) {
  ZenLogger.logDebug(
      '🧪 Test Mode: Mocking $T${tag != null ? ':$tag' : ''} (${alwaysNew ? 'always new' : 'lazy singleton'})');

  Zen.delete<T>(tag: tag, force: true);
  Zen.putLazy<T>(factory, tag: tag, alwaysNew: alwaysNew);

  return this;
}