Skip to content

DiagnosticableMixin.toString' ('String Function({minLevel: DiagnosticLevel}) isnt a valid override of 'Mock.toString' ('String Function()'). #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SenadK95 opened this issue Jan 6, 2020 · 7 comments
Labels
type-question A question about expected behavior or functionality

Comments

@SenadK95
Copy link

SenadK95 commented Jan 6, 2020

'Hello i keep getting the following error while using mockito :

DiagnosticableMixin.toString' ('String Function({minLevel: DiagnosticLevel}) isnt a valid override of 'Mock.toString' ('String Function()').

i already tried :
abstract class MockWithExpandedToString extends Mock {
String toString({ DiagnosticLevel minLevel = DiagnosticLevel.debug });
}
but this didn't work for me.

import 'package:mockito/mockito.dart';
class TestData extends MockWithExpandedToString implements BookingFormState {}

anyone knows how to fix this ?

@srawlins
Copy link
Member

srawlins commented Jan 7, 2020

You mention that this looks similar to #228, but your two code snippets do not reference each other:

abstract class MockWithExpandedToString extends Mock {
String toString({ DiagnosticLevel minLevel = DiagnosticLevel.debug });
}

and

import 'package:mockito/mockito.dart';
class TestData extends Mock implements BookingFormState {}

Should TestData extend MockWithExpandedToString instead of Mock?

@SenadK95
Copy link
Author

SenadK95 commented Jan 7, 2020

Yes you're right, i updated my first comment. I tried it with MockWithExpandedToString but no succes. You have any idea what else it can be @srawlins ?

@srawlins
Copy link
Member

srawlins commented Jan 7, 2020

We need a complete, reproducing example. I don't see where BookingFormState is. I don't see how DiagnosticLevel is imported.

I don't think "DiagnosticableMixin.toString' ('String Function({minLevel: DiagnosticLevel}) isnt a valid override of 'Mock.toString' ('String Function()')." would show up if TestData extends MockWithExpandedToString instead of Mock. The message doesn't spell "isn't" correctly which is very suspicious.

@SenadK95
Copy link
Author

SenadK95 commented Jan 8, 2020

@srawlins The reason why "isn't" was misspelled was because of me. I didn't copy the error but typed it over. For my code i made a repository : https://github.com/SenadK95/vitalforest .

@srawlins
Copy link
Member

srawlins commented Jan 9, 2020

Thanks for uploading a code repo. It does not reference Mockito though.

@leecommamichael
Copy link

This is really easy to reproduce if you attempt to mock a widget that inherits from InheritedWidget.

@natebosch
Copy link
Member

Adding the manual override of toString() to fit the signature does work. Here is the minimal example:

This has static errors:

import 'package:mockito/mockito.dart';

class Foo {
  @override
  String toString({String extra}) => extra ?? 'default';
}

class MockFoo extends Mock implements Foo {}

This fixes the errors:

import 'package:mockito/mockito.dart';

class Foo {
  @override
  String toString({String extra}) => extra ?? 'default';
}

class MockFoo extends Mock implements Foo {
  @override
  String toString({String extra}) => super.toString();
}

You can either copy/paste this into your mocks:

  @override
  String toString({ DiagnosticLevel minLevel = DiagnosticLevel.debug }) => super.toString();

Or you can define it once:

abstract class MockWithDiagnosticToString extends Mock {
  @override
  String toString({ DiagnosticLevel minLevel = DiagnosticLevel.debug }) => super.toString();
}

Then replace extends Mock with extends MockWithDiagnosticToString any place that needs it. Note that in the first 2 comments the definition of toString was abstract - it did not provide a body. Replace the ; with => super.toString(); to fix this.

Closing since this can be worked around locally and there are no actions to take in this package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-question A question about expected behavior or functionality
Projects
None yet
Development

No branches or pull requests

4 participants