Skip to content

"type 'Null' is not a subtype of type" on getter #608

Open
@AdrienAudouard

Description

@AdrienAudouard

Hello,

I'm trying to generate a mock for a class witch contains a getter, the source code of the class is:

class AppContext {
...
  AppLocalizations get l10n => AppLocalizations.of(navigatorMaterialAppKey.currentContext!);
}

Then I generate a mock of the class with mockito and with the following code:

@GenerateNiceMocks([
  MockSpec<AppContext>(),
])

When I run the tests I have the following error: type 'Null' is not a subtype of type 'AppLocalizations', it look like in the generated code, the mock code of the getter is not generated.

Can you help me please ? 🙏

The generated code:

/// A class which mocks [AppContext].
///
/// See the documentation for Mockito's code generation for more information.
class MockAppContext extends _i1.Mock implements _i81.AppContext {
  @override
  _i28.GlobalKey<_i28.NavigatorState> get navigatorMainPageKey =>
      (super.noSuchMethod(
        Invocation.getter(#navigatorMainPageKey),
        returnValue: _FakeGlobalKey_34<_i28.NavigatorState>(
          this,
          Invocation.getter(#navigatorMainPageKey),
        ),
        returnValueForMissingStub: _FakeGlobalKey_34<_i28.NavigatorState>(
          this,
          Invocation.getter(#navigatorMainPageKey),
        ),
      ) as _i28.GlobalKey<_i28.NavigatorState>);
  @override
  _i28.GlobalKey<_i28.NavigatorState> get navigatorVaultKey =>
      (super.noSuchMethod(
        Invocation.getter(#navigatorVaultKey),
        returnValue: _FakeGlobalKey_34<_i28.NavigatorState>(
          this,
          Invocation.getter(#navigatorVaultKey),
        ),
        returnValueForMissingStub: _FakeGlobalKey_34<_i28.NavigatorState>(
          this,
          Invocation.getter(#navigatorVaultKey),
        ),
      ) as _i28.GlobalKey<_i28.NavigatorState>);
  @override
  _i28.GlobalKey<_i28.NavigatorState> get navigatorMaterialAppKey =>
      (super.noSuchMethod(
        Invocation.getter(#navigatorMaterialAppKey),
        returnValue: _FakeGlobalKey_34<_i28.NavigatorState>(
          this,
          Invocation.getter(#navigatorMaterialAppKey),
        ),
        returnValueForMissingStub: _FakeGlobalKey_34<_i28.NavigatorState>(
          this,
          Invocation.getter(#navigatorMaterialAppKey),
        ),
      ) as _i28.GlobalKey<_i28.NavigatorState>);
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions