You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I hope you're all doing great. I'm facing some challenges while writing widget tests that involve form validation using a mocked GetXController.
The scenario is that I have a form with various input fields and I'm using a GetXController to manage the form state and validation logic. Everything works fine in the app itself, but when it comes to writing widget tests, especially for scenarios involving form validation, I'm hitting a roadblock.
i have a TextEditingController for email and password input & a GlobalKey<FormState> inside the controller, when i use mock using this code class MockLoginController extends GetxController with Mock implements LoginController it gives an error that i should override TextEditingControler & GlobalKey<FormState>. I have done that and now when i run the test it always give me Null check operator used on a null value error on this code formKey.currentState!.validate()
i have tried widget test without mocking the controller and it works, but since in the real world application have a API call to make inside login function i have to mock the function
Some specific questions I have:
- How do you mock the GetXController in a widget test scenario?
- What's the best way to simulate user interactions to trigger form validation and error messages?
- Are there any common pitfalls or gotchas that I should be aware of while testing form validation with GetX?
I'm really looking forward to learning from your experiences and insights. Any help would be greatly appreciated!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey fellow developers,
I hope you're all doing great. I'm facing some challenges while writing widget tests that involve form validation using a mocked GetXController.
The scenario is that I have a form with various input fields and I'm using a GetXController to manage the form state and validation logic. Everything works fine in the app itself, but when it comes to writing widget tests, especially for scenarios involving form validation, I'm hitting a roadblock.
i have a
TextEditingController
for email and password input & aGlobalKey<FormState>
inside the controller, when i use mock using this codeclass MockLoginController extends GetxController with Mock implements LoginController
it gives an error that i should overrideTextEditingControler
&GlobalKey<FormState>
. I have done that and now when i run the test it always give meNull check operator used on a null value
error on this codeformKey.currentState!.validate()
i have tried widget test without mocking the controller and it works, but since in the real world application have a API call to make inside login function i have to mock the function
Some specific questions I have:
I'm really looking forward to learning from your experiences and insights. Any help would be greatly appreciated!
Thanks in advance. Happy coding!
Beta Was this translation helpful? Give feedback.
All reactions