-
Notifications
You must be signed in to change notification settings - Fork 248
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
Testing with Jest fireEvent.press() #243
Comments
Update: Before:
After:
So now there are two copies of the onPress logic and it looks like hell, but it works! A snippet from the test:
Note: I am using the jest.mock from my previous comment to make this work. If anybody comes up with a better way, I'm all ears. |
I struggled with this for a while, but I think I found an excellent way to test this out. The only issue with your method is that when you put
then to test this you can try something like this
You can see that I used |
I mentioned this in #197 but that one is closed, so it neede a new issue.
Has anyone gotten Jest fireEvent.press() working?
In the testing example, they suggest mocking all the components like this:
jest.mock('react-native-popup-menu', () => ({
Menu: 'Menu',
MenuProvider: 'MenuProvider',
MenuOptions: 'MenuOptions',
MenuOption: 'MenuOption',
MenuTrigger: 'MenuTrigger',
}));
See Example: https://github.com/instea/react-native-popup-menu/blob/master/examples/__tests__/Basic-test.js
However, mocking all the components makes them no longer function. So trying to use fireEvent.press() on them to test actual functionality doesn't work at all.
I tried not mocking the components, but then Jest cannot find them at all, and the tests fail there, so I'm back to square one.
The text was updated successfully, but these errors were encountered: