Open anas2027 opened 1 month ago
i find a the soultion :)
just replace this import
import 'package:mockito/mockito.dart';
to this
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); }
}`
How is this related to the flutter_native_splash
package?
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