Skip to content
New issue

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

Get.context is null during unit tests #695

Closed
papmodern opened this issue Oct 9, 2020 · 4 comments
Closed

Get.context is null during unit tests #695

papmodern opened this issue Oct 9, 2020 · 4 comments
Labels
expected behavior it is not a bug Not an issue This issue does not have any bug report or feature request, so it does not qualify as a valid issue

Comments

@papmodern
Copy link

I am using mobx for state management and before adding get package to my project, I was passing the context to each action I needed to. Now by the help of Get.context, I remove all the context inputs from my actions. But during tests, this context is empty and it seems Get won't initialize itself correctly.

It would be great if there was a tool to initialize Get before tests, if it exists, I couldn't find it through the docs.

I think we need a separated section in docs related to testing. The ways that we can solve the anti-pattern dependency handling of Get in our tests.

@ghenry
Copy link

ghenry commented Oct 9, 2020

Try this way? #418 (comment)

@ghenry
Copy link

ghenry commented Oct 9, 2020

Are you using getmateralapp?

@papmodern
Copy link
Author

Are you using getmateralapp?

I am writing unit test. Just initiating a class and testing methods.

@jonataslaw jonataslaw added expected behavior it is not a bug Not an issue This issue does not have any bug report or feature request, so it does not qualify as a valid issue labels Oct 9, 2020
@jonataslaw
Copy link
Owner

Get.context is null if you don't have a GetMaterialApp to provide the context.

Add something like:
await tester.pumpWidget(GetMaterialApp(home: Scaffold()));
or use the "getTest" from get_test package to made tests without worrying about the context.

As this is expected behavior, I am closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expected behavior it is not a bug Not an issue This issue does not have any bug report or feature request, so it does not qualify as a valid issue
Projects
None yet
Development

No branches or pull requests

3 participants