debugEmbraceOverride top-level property

  1. @visibleForTesting
Embrace? debugEmbraceOverride
getter/setter pair

A variable that can be used to override Embrace.instance for mocking in unit tests. If set to a non-null value, Embrace.instance will return this instead of its default behavior.

This should not be used in production Flutter code. It is only intended to aid in testing.

class MockEmbrace extends Mock implements Embrace {}

void main() {
  test('mocking embrace instances', () {
    final mockEmbrace = MockEmbrace();
    debugEmbraceOverride = mockEmbrace;
    expect(Embrace.instance, mockEmbrace);

    // You can reset [Embrace.instance] by setting [debugEmbraceOverride] to `null`;
    debugEmbraceOverride = null
    expect(Embrace.instance, isNot(mockEmbrace));
  });
}

Implementation

@visibleForTesting

/// A variable that can be used to override [Embrace.instance] for
/// mocking in unit tests. If set to a non-null value, [Embrace.instance]
/// will return this instead of its default behavior.
///
/// This **should not** be used in production Flutter code. It is **only**
/// intended to aid in testing.
///
/// ```dart
/// class MockEmbrace extends Mock implements Embrace {}
///
/// void main() {
///   test('mocking embrace instances', () {
///     final mockEmbrace = MockEmbrace();
///     debugEmbraceOverride = mockEmbrace;
///     expect(Embrace.instance, mockEmbrace);
///
///     // You can reset [Embrace.instance] by setting [debugEmbraceOverride] to `null`;
///     debugEmbraceOverride = null
///     expect(Embrace.instance, isNot(mockEmbrace));
///   });
/// }
/// ```
Embrace? debugEmbraceOverride;