Skip to content
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

mocktail gives confusing errors when there is an incomplete mock #237

Closed
erickzanardo opened this issue Apr 19, 2024 · 2 comments
Closed
Labels
duplicate This issue or pull request already exists

Comments

@erickzanardo
Copy link

erickzanardo commented Apr 19, 2024

Describe the bug

If you make an incomplete mock, like calling when but forgetting to call thenReturn or thenAnswer, when you start a new mock, mocktail will break on that line, making you think that the issue is there, when it actually isn't, making it hard to track the error.

To Reproduce

import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

class _MockFoo extends Mock implements Foo {}

class Foo {
  const Foo({
    required Map<String, dynamic> data,
  }) : _data = data;
  final Map<String, dynamic> _data;

  dynamic operator [](String key) => _data[key];

  String sayHello() => 'Hello, ${_data['Name']}!';
}

void main() {

  late Foo foo;

  setUp(() {
    foo = _MockFoo();
    when(() => foo['Name']); // <- This is incomplete
  });

  test('say hello, says hello', () {
    when(() => foo.sayHello()).thenReturn('Hello, Bond, James Bond!'); // <- Test will break here, but this mock is fine
    expect(foo.sayHello(), 'Hello, Bond, James Bond!');
  });
}

Expected behavior
I understand that it might be hard to break in the incomplete mock, but maybe the messaging could at least be improved, since in a big test file, tracking down this type of error can be quite challenging.

@felangel felangel added the enhancement New feature or request label Apr 20, 2024
@felangel
Copy link
Owner

Seems like a duplicate of #213

@felangel felangel added the duplicate This issue or pull request already exists label Apr 20, 2024
@felangel
Copy link
Owner

Closing in favor of #213

@felangel felangel removed the enhancement New feature or request label Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants