Ken Verganio
Ken Verganio

Reputation: 645

The argument type 'Future<User> Function(Invocation)' can't be assigned to the parameter type 'Future<User> Function() Function(Invocation)'

Hello im writing a test using mockito but when i try to use the example in mockito documentation it throws an error for me,

Im asking what is the right syntax for the function inside the thenAsnswer?

ERROR: The argument type 'Future Function(Invocation)' can't be assigned to the parameter type 'Future Function() Function(Invocation)'

   test(
  "GIVEN success call WHEN login called THEN return User",
  () async {
    //arrange
    when(
      () => service.login(credentials: credential),
    ).thenAnswer(
      (_) async => Future.value(user),
    );

    //act
    final futureUser =   await service.login(
      credentials: credential,
    );

    //assert
    expect( futureUser, user);
  },
);

Upvotes: 0

Views: 472

Answers (1)

BHARATH T
BHARATH T

Reputation: 682

Just replace

when(
  () => service.login(credentials: credential),
).thenAnswer(
  (_) async => Future.value(user),
);

with

when(
  service.login(credentials: credential),
).thenAnswer(
  (_) async => Future.value(user),
);

Happy coding :)

Upvotes: 2

Related Questions