How to use the react-native-testing-library.fireEvent 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 / components / theme / application / application.spec.tsx View on Github external
it('* theme switching checks', () => {
    const application: RenderAPI = render();
    fireEvent(application.getByType(Button), 'press');
    const { output } = shallow(application.getByType(ApplicationProvider));

    const stringify = (obj: any): string => {
      return JSON.stringify(obj);
    };

    // @ts-ignore just for theme prop changing
    expect(stringify(output.props.theme)).toBe(JSON.stringify(themeInverse));
  });
github paularmstrong / build-tracker / src / app / src / components / __tests__ / DrawerLink.tsx View on Github external
test('changes font color', () => {
      const { getByType } = render();
      const root = getByType(Text);
      expect(StyleSheet.flatten(root.props.style)).not.toMatchObject({
        color: expect.any(String)
      });
      fireEvent(root, 'mouseEnter');
      expect(StyleSheet.flatten(root.props.style)).toMatchObject({
        color: Theme.Color.Primary40
      });
    });
  });
github paularmstrong / build-tracker / src / app / src / components / __tests__ / DrawerLink.tsx View on Github external
test('adds a bg color', () => {
      const { getByProps } = render();
      const root = getByProps({ accessibilityRole: 'link' });
      expect(StyleSheet.flatten(root.props.style)).not.toMatchObject({
        backgroundColor: expect.any(String)
      });
      fireEvent(root, 'mouseEnter');
      expect(StyleSheet.flatten(root.props.style)).toMatchObject({
        backgroundColor: Theme.Color.Primary00
      });
    });
github akveo / react-native-ui-kitten / src / components / ui / checkbox / checkbox.spec.tsx View on Github external
it('* touchable other props', () => {
    const onPressIn = jest.fn();
    const onPressOut = jest.fn();
    const component: RenderAPI = renderComponent({
      onPressIn: onPressIn,
      onPressOut: onPressOut,
    });

    fireEvent(component.getByType(TouchableOpacity), 'pressIn');
    fireEvent(component.getByType(TouchableOpacity), 'pressOut');

    expect(onPressIn).toHaveBeenCalled();
    expect(onPressOut).toHaveBeenCalled();
  });
github akveo / react-native-ui-kitten / src / components / ui / toggle / toggle.spec.tsx View on Github external
it('checking of value reverse', () => {
    let checked: boolean = true;
    const onChangeValue = (changed: boolean) => {
      checked = changed;
    };

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

    const { [0]: containerView } = component.getByType(ToggleComponent).children;

    fireEvent(containerView as ReactTestInstance, 'responderRelease');

    expect(checked).toBe(false);
  });
github akveo / react-native-ui-kitten / src / components / ui / radio / radio.spec.tsx View on Github external
it('active checked', async () => {
    const component: RenderAPI = renderComponent({ checked: true });

    fireEvent(component.getByType(TouchableOpacity), 'pressIn');

    const active: ReactTestInstance = await waitForElement(() => {
      return component.getByType(Radio);
    });
    const { output: activeOutput } = shallow(active);

    fireEvent(component.getByType(TouchableOpacity), 'pressOut');

    const inactive: ReactTestInstance = await waitForElement(() => {
      return component.getByType(Radio);
    });
    const { output: inactiveOutput } = shallow(inactive);

    expect(activeOutput).toMatchSnapshot();
    expect(inactiveOutput).toMatchSnapshot('checked');
  });
github akveo / react-native-ui-kitten / src / components / ui / input / input.spec.tsx View on Github external
it('* emits onBlur', () => {
    const onBlur = jest.fn();

    const component: RenderAPI = renderComponent({ onBlur });

    fireEvent(component.getByType(TextInput), 'blur');

    expect(onBlur).toBeCalled();
  });
github akveo / react-native-ui-kitten / src / components / ui / menu / menu.spec.tsx View on Github external
it('* menu item onPress prop checks', () => {
    const onPress = jest.fn();
    const title: string = 'Option';

    const menuItem: RenderAPI = render(
      
        <menuitem title="{title}">
      </menuitem>,
    );

    fireEvent(menuItem.getAllByText(title)[0], 'press');

    expect(onPress).toHaveBeenCalled();
  });
github akveo / react-native-ui-kitten / src / components / ui / menu / menu.spec.tsx View on Github external
const onLongPress = jest.fn();
    const title: string = 'Option';

    const menuItem: RenderAPI = render(
      
        <menuitem title="{title}">
      </menuitem>,
    );

    fireEvent(menuItem.getAllByText(title)[0], 'press');
    fireEvent(menuItem.getAllByText(title)[0], 'pressIn');
    fireEvent(menuItem.getAllByText(title)[0], 'pressOut');
    fireEvent(menuItem.getAllByText(title)[0], 'longPress');

    expect(onLongPress).toHaveBeenCalled();
  });
github akveo / react-native-ui-kitten / src / framework / ui / tabNavigator / bottomTabNavigator.spec.tsx View on Github external
icon={(style: StyleType) =&gt; <img style="{style}/">}
          title='Screen 1'
          selected={false}/&gt;
         <img style="{style}/">}
          title='Screen 2'
          selected={true}/&gt;
         <img style="{style}/">}
          title='Screen 3'
          selected={false}/&gt;
      ,
    );

    fireEvent(component.getByTestId(tabTestId), 'select');

    expect(component).toMatchSnapshot();
    expect(onSelect).toHaveBeenCalled();
  });

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

65 / 100
Full package analysis