-
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
e2e testing using testID and customStyles #197
Comments
This works for MenuTrigger, but no testID is showing up for MenuOption for me. I'm using Jest and React Native. |
For me it is working ok testing 4/5 different MenuOptions. And I checked back at MenuOptions source code:
So |
PRs are welcomed :) supporting |
I work on the e2e PR ;-) |
Yep but I think it should be named customProps instead of customStyle ? |
well... most of those are styles, but this is "exception" as you need props
to style touchable....
…On Fri, Dec 11, 2020 at 2:26 PM Mik ***@***.***> wrote:
Yep but I think it should be named customProps instead of customStyle ?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#197 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABOZEI2KIXAGI7U3GKKMBP3SUIMXVANCNFSM4UTVUPOA>
.
|
but yes, it is suboptimal name. |
The popup menu works fine on iOS/Android simulators, but I'm trying to use Jest to run tests. I'm trying to use React Native Testing Library such that I can find a MenuOption by it's testID, click on that option, and then test my own code. But fireEvent.press() isn't finding the MenuOption's testID. And when I use Jest's snapshot feature, I can find the testID of MenuTrigger, but I can't find any MenuOption's testID's. I copied the code that you wrote: |
@sjmdocto you should test latest version 0.15.10. I added support for testID in MenuOption and MenuTrigger |
Hey @sjmdocto did you find a solution for this? Exact same use case. Should also be noted I'm on version 0.15.12 @mikbry - looks like |
Has anyone gotten Jest fireEvent.press() working? |
No
|
still not working for me using RNTL fireevent.press is not opening my menu @sodik82 |
I've had success with mocking both For example, import type * as ReactNative from 'react-native';
// Mock react-native to modify View's constructor.
jest.mock('react-native', () => {
// See https://jestjs.io/docs/jest-object#jestrequireactualmodulename
const reactNative = jest.requireActual<typeof ReactNative>('react-native');
const ViewMock = class extends reactNative.View {
public constructor(props: ReactNative.ViewProps) {
super(props);
// react-native-popup-menu won't show menus until an onLayout event is fired on
// a View just within its MenuProvider.
// To work around this, call onLayout for all View components.
if (this.props.onLayout) {
this.props.onLayout({ nativeEvent: { layout: { x: 0, y: 0, width: 100, height: 100 } }} as any);
}
}
// The layout for a MenuTrigger is found using .measure. Mock .measure to allow
// triggers to display menus:
public measure = (callback: ReactNative.MeasureOnSuccessCallback) => {
callback(0, 0, 150, 150, 0, 0);
};
};
// Use a Proxy object, rather than {...reactNative, View: ViewMock}. React Native warns
// when attempting to access certain deprecated properties (which is done by ...reactNative).
return new Proxy(reactNative, {
get(target, property) {
if (property === 'View') {
return ViewMock;
}
return target[property as keyof typeof ReactNative];
},
});
}); Then in a test, ...
test('example test', async () => {
render(<MyComponent/>);
// Note: Add testID='menu-trigger-button' to the MenuTrigger:
const trigger = await screen.findByTestId('menu-trigger-button');
const user = userEvent.setup();
user.press(trigger);
// The menu should now be open.
}); |
This component is not designed for e2e testing, see #155.
But i found a workaround using customStyles. In fact customStyles are more customProps for sub-components.
For MenuTrigger:
For MenuOption:
Tested using Detox on Android emulator
The text was updated successfully, but these errors were encountered: