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

Make PostExpectation generic. #98

Closed
grouma opened this issue Feb 14, 2018 · 6 comments
Closed

Make PostExpectation generic. #98

grouma opened this issue Feb 14, 2018 · 6 comments

Comments

@grouma
Copy link
Member

grouma commented Feb 14, 2018

An error cropping up while migrating tests to Dart 2.0 semantics is having invalid return types for thenAnswer which cause runtime issues.
For example consider the class Foo:

class Foo {
    Future<B> doSomething(A a);
}

Set up the mock for Foo as follows:

MockFoo foo = new MockFoo()
when(foo.doSomething(any(a)).thenAnswer((_) => new B())

The above will currently run without issue in the VM. However, the return type of thenAnswer is invalid as it should be returning Future<B> instead of the raw B value. I believe we can catch these errors through analysis. when uses PostExpectation which can be made generic. This will allow us to enforce the return type of thenAnswer accordingly.

@srawlins
Copy link
Member

Sounds good. Maybe specifically Answering needs to be type annotated? https://github.com/dart-lang/mockito/blob/master/lib/src/mock.dart#L605

@grouma
Copy link
Member Author

grouma commented Feb 14, 2018

I'm not sure if that will help. We need to have a return type here: https://github.com/dart-lang/mockito/blob/master/lib/src/mock.dart#L320

@srawlins
Copy link
Member

Ah I see. Do you see any way to type the T in PostExpectation<T>?

@grouma
Copy link
Member Author

grouma commented Feb 15, 2018

I think the type should be coming from here: https://github.com/dart-lang/mockito/blob/master/lib/src/mock.dart#L744

@srawlins
Copy link
Member

Yeah I can see it. Sounds good, I'll accept a PR.

@srawlins
Copy link
Member

Fixed with #101

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants