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

detox throws error when metro is run with mocks #645

Open
Mister-CK opened this issue Mar 11, 2024 · 2 comments
Open

detox throws error when metro is run with mocks #645

Mister-CK opened this issue Mar 11, 2024 · 2 comments

Comments

@Mister-CK
Copy link

When running detox with metro in mock mode. It should mock the createMMKV call. The check for this is based on a platform checker that checks isJest(). I don't think this is a good way to do this or the way metro has intended.
image

The way metro works is that you configure it to prefer mock files over regular files when run in mock mode, through the sourceExts in your metro config. So it will completely ignore the regular file and use the .mock file instead.
This means in the current setup that the regular createMMKV() function will not exist. This is not a good practice. What you should do instead is import only from './createMMKV'. and give the mock version of the call in your .mock file the same name. This way the call will always exist and the mock variant is picked based on how metro is started, not based on if you are running with jest (that call didn't work for me). Refactoring this might break some existing logic though. So what I did is I created a patch with PlatformChecker.mock.js which contained isJest() => true; this works because when metro is started in mock mode it will pick the isJest call from the mock file and always return true. Which I think is a better check than actually checking for jest. since the calls are dependant on mock files, not jest. I don't think this breaks the existing logic.

@mrousavy
Copy link
Owner

Hey - thanks for your suggestions, could you submit a PR to fix this? We can test if this breaks existing behaviour or not.

@Mister-CK
Copy link
Author

Thanks for the quick reply, I will see if I can make a PR with the changes tonight

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants