mocktail icon indicating copy to clipboard operation
mocktail copied to clipboard

Try catch block in test

Open LScodeblack opened this issue 6 months ago • 0 comments

is the below a good approach as without the try catch block the test will fail.

` test("login fails, user session isnt stored", () async { //arrange when(() => authRepository.login(email, password)).thenThrow(Exception());

  //act
  try {
    await authService.login(email, password);
  } catch (error) {
    //error caught
  }

  //expect
  verifyNever(() => hiveRepository.storeToken(dummyToken));
  verifyNever(() => hiveRepository.storeIsLoggedIn(true));
});`

LScodeblack avatar Aug 22 '24 07:08 LScodeblack