I have a component that reads from context the current (FirebaseAuth) User and checks whether it is null or not. It works in dev, however, when I want to test it with mock values, it does not.
I have mocked the auth User like so:
class MockFirebaseAuth extends Mock implements FirebaseAuth {}
var mockAuth = MockFirebaseAuth();
when(mockAuth.currentUser).thenReturn(mockUser);
when(mockAuth.authStateChanges())
.thenAnswer((_) => Stream.fromIterable([mockUser]));
So here how the test looks:
await tester.pumpWidget(
MultiProvider(
providers: [
Provider<AuthService>(
create: (context) => AuthService(mockAuth, mockFireInstance),
),
StreamProvider<User>(
create: (context) => context.read<AuthService>().authStateChanges,
),
],
child: MaterialApp(
home: SettingEmail(),
),
),
);
That is how I access the User stream from a TextFormField:
validator: (value) {
var user = context.read<User>();
if (user.email != currentEmailController.text) {
return 'Email adresinizi doğru girdiğinizden emin olunuz';
}
return null;
},
then I get the following error:
The following NoSuchMethodError was thrown running a test:
The getter 'email' was called on null.
Receiver: null
Tried calling: email
So, how can I access that mockUser from that validator during unit test?
Aucun commentaire:
Enregistrer un commentaire