How to use the react-native-testing-library.fireEvent.press function in react-native-testing-library

To help you get started, we’ve selected a few react-native-testing-library examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github akveo / react-native-ui-kitten / src / framework / theme / component / modal / modalPanel.spec.tsx View on Github external
it('* close modal checking inner', () => {
    const component: RenderAPI = render(
      ,
    );

    fireEvent.press(component.getByTestId(showModalTestId));
    fireEvent.press(component.getByTestId(hideModalTestIdInner));

    const { output } = shallow(component.getByType(ModalPanel));

    expect(output).toMatchSnapshot();
  });
github akveo / react-native-ui-kitten / src / components / ui / radioGroup / radioGroup.spec.tsx View on Github external
it('* emits `onChange` with correct args', () => {
    const onChange = jest.fn();

    const component: RenderAPI = render(
      
        
        
      ,
    );

    const radio: ReactTestInstance = component.getByTestId(childTestId1);
    const touchable: ReactTestInstance = radio.findByType(TouchableOpacity);

    fireEvent.press(touchable);

    expect(onChange).toBeCalledWith(1);
  });
github akveo / react-native-ui-kitten / src / components / ui / radio / radio.spec.tsx View on Github external
it('* emits onChange with correct args', () => {
    const onChange = jest.fn();

    const component: RenderAPI = renderComponent({
      checked: false,
      onChange: onChange,
    });

    fireEvent.press(component.getByType(TouchableOpacity));

    expect(onChange).toBeCalledWith(true);
  });
github akveo / react-native-ui-kitten / src / components / ui / calendar / calendar.spec.tsx View on Github external
it('* should change year to previous', () => {
    const calendarRef: React.LegacyRef = React.createRef();
    const application: RenderAPI = render(
      ,
    );

    const initialDate = calendarRef.current.state.visibleDate;
    fireEvent.press(application.getAllByType(TouchableOpacity)[1]);
    const visibleDate = calendarRef.current.state.visibleDate;

    const expectedDate = new Date(initialDate.getFullYear() - 12, initialDate.getMonth(), initialDate.getDate());
    expect(visibleDate).toEqual(expectedDate);
  });
github akveo / react-native-ui-kitten / src / components / ui / modal / modal.spec.tsx View on Github external
it('* modal default center placement calculated properly', () => {
    const window: Frame = Frame.window();
    const modalStyle: StyleType = {
      width: 200,
      height: 200,
    };
    const component: RenderAPI = render(
      ,
    );

    fireEvent.press(component.getByTestId(buttonShowModalTestId));
    const modalInstance: any = component.getByType(Modal).instance;
    const expectedStyle: StyleType = {
      top: (window.size.height - modalInstance.contentSize.height) / 2,
      left: (window.size.width - modalInstance.contentSize.width) / 2,
    };

    const baseModalStyles: StyleType[] = component.getByTestId(baseModalTestId).props.style;
    const expectedStyleExist: boolean = baseModalStyles[0]
      .some((style: StyleType) => stringify(style) === stringify(expectedStyle));

    expect(expectedStyleExist).toBe(true);
  });
github akveo / react-native-ui-kitten / src / components / ui / menu / menu.spec.tsx View on Github external
it('* group menu works properly', () => {
    const expectedSelectedItem: MenuItemType = { title: 'Option 32' };
    const application: RenderAPI = render(
      ,
    );

    fireEvent.press(application.getAllByText('Option 3')[0]);
    const { selectedIndex: selectedIndex1 } = application.getByType(Menu).props;
    expect(selectedIndex1).toBeNull();

    fireEvent.press(application.getAllByText('Option 32')[0]);
    const { selectedIndex: selectedIndex2 } = application.getByType(Menu).props;
    expect(selectedIndex2).toBe(3);
  });
github akveo / react-native-ui-kitten / src / components / ui / button / button.spec.tsx View on Github external
it('* emits onPress', () => {
    const onPress = jest.fn();

    const component: RenderAPI = renderComponent({
      onPress: onPress,
    });

    fireEvent.press(component.getByType(TouchableOpacity));

    expect(onPress).toBeCalled();
  });
github akveo / react-native-ui-kitten / src / components / theme / theme / theme.spec.tsx View on Github external
it('* able to change theme', async () => {
    const component: RenderAPI = render(
      ,
    );

    const touchableComponent: ReactTestInstance = component.getByTestId(themeChangeTouchableTestId);

    fireEvent.press(touchableComponent);

    const themedComponent: ReactTestInstance = await waitForElement(() => {
      return component.getByTestId(themeConsumerTestId);
    });

    const { theme: themeProp } = themedComponent.props;

    expect(json(themeProp)).toEqual(json(themeInverse));
  });
github akveo / react-native-ui-kitten / src / components / ui / topNavigation / topNavigation.spec.tsx View on Github external
onPress={onRightControl2}
          />,
          ,
        ]}
      />,
    );
    const { output } = shallow(component.getByType(TopNavigation));

    expect(output).toMatchSnapshot();

    fireEvent.press(component.getByTestId(testIdLeftAction));
    fireEvent.press(component.getByTestId(testIdRightAction1));
    fireEvent.press(component.getByTestId(testIdRightAction2));
    fireEvent.press(component.getByTestId(testIdRightAction3));

    expect(onLeftControl).toHaveBeenCalled();
    expect(onRightControl1).toHaveBeenCalled();
    expect(onRightControl2).toHaveBeenCalled();
    expect(onRightControl3).toHaveBeenCalled();
  });
github akveo / react-native-ui-kitten / src / components / theme / style / style.spec.tsx View on Github external
const component: RenderAPI = render(
      
        
      ,
    );

    const styledComponent: ReactTestInstance = component.getByTestId(styleConsumerTestId);

    expect(styledComponent.props.themedStyle).toMatchSnapshot();

    const touchableComponent: ReactTestInstance = component.getByTestId(styleTouchableTestId);

    fireEvent.press(touchableComponent);

    const styledComponentChanged: ReactTestInstance = await waitForElement(() => {
      return component.getByTestId(styleConsumerTestId);
    });

    expect(styledComponentChanged.props.themedStyle).toMatchSnapshot();
  });

react-native-testing-library

Simple React Native testing utilities helping you write better tests with less effort

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis