We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
when()
abstract class HomeRepository { Future<Either<Failure,BaseModel>> testCase({required ApiRequest apiRequest}); }
class TestCase { HomeRepository homeRepository; TestCase({required this.homeRepository}); Future<Either<Failure,BaseModel>>call({required ApiRequest apiRequest})async{ return await homeRepository.testCase(apiRequest: apiRequest); } }
### now here is my test page
class HomeTest extends Mock implements HomeRepository{ @override Future<Either<Failure,BaseModel>> testCase({required ApiRequest apiRequest})async{ return await Right(AppModel.otpVerify); } } void main(){ ApiRequest apiRequest = ApiRequest(method: ApiMethod.post, endPoint: '/'); late HomeTest homeTest; late TestCase testCase; setUp(() { homeTest = HomeTest(); testCase = TestCase(homeRepository: homeTest); }); test('testcase', () async { // Setup when(homeTest.testCase(apiRequest: apiRequest)).thenAnswer((_) async => right(AppModel.otpVerify)); // Action final result = await testCase(apiRequest: apiRequest); // Verification expect(result, right(AppModel.otpVerify)); // Ensure the expected result matches the actual result }); }
The text was updated successfully, but these errors were encountered:
i find a the soultion :) just replace this import import 'package:mockito/mockito.dart'; to this import 'package:mocktail/mocktail.dart';
import 'package:mocktail/mocktail.dart';
class MockAuthRepo extends Mock implements AuthRepositories { @override Future<Either<Failure, BaseModel>> testCase({required ApiRequest apiRequest}) async { return await Future.value(right(AppModel.otpVerify)); } } void main() { late MockAuthRepo mockAuthRepo; late PhoneVerifyUseCase useCase; OtpPageModel otpPageModel = OtpPageModel(phoneNumber: '0939048067'); ApiRequest apiRequest = ApiRequest( method: ApiMethod.post, endPoint: EndPoints.login, model: AppModel.loginModel, body: otpPageModel.toJson(), ); setUp(() { mockAuthRepo = MockAuthRepo(); useCase= PhoneVerifyUseCase(authRepositories: mockAuthRepo); }); test('should get trivia for the number from the repository', () async{ // Setup when(() => mockAuthRepo.phoneVerify(apiRequest: apiRequest)) .thenAnswer((_) async => right(AppModel.loginModel)); // Action final result = await useCase(apiRequest: apiRequest); // Verification expect(result, Right(AppModel.loginModel)); }); }
and the repo is
abstract class AuthRepositories{ Future<Either<Failure,BaseModel>> phoneVerify({required ApiRequest apiRequest}); Future<Either<Failure,BaseModel>> otpVerify({required ApiRequest apiRequest}); Future<Either<Failure,BaseModel>> getAppOptions({required ApiRequest apiRequest}); }
and the use case is ` class PhoneVerifyUseCase{ AuthRepositories authRepositories ; PhoneVerifyUseCase({required this.authRepositories});
Future<Either<Failure,BaseModel>>call({required ApiRequest apiRequest})async{ return await authRepositories.phoneVerify(apiRequest: apiRequest); }
}`
Sorry, something went wrong.
How is this related to the flutter_native_splash package?
flutter_native_splash
No branches or pull requests
Bad state: No method stub was called from within
when()
. Was a real method called, or perhaps an extension method?here my repo
here my usecase
### now here is my test page
The text was updated successfully, but these errors were encountered: