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

To help you get started, we’ve selected a few react-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 timc1 / time-capsule / src / components / questionnaire / __tests__ / steps / interests.js View on Github external
test(`User should be able to add a new checkbox item.`, async () => {
    const { getByText, getByTestId, getAllByTestId } = render()
    const modalToggle = getByTestId('modal-toggle')
    // Open menu.
    const menuToggle = getByText(/More/i)
    fireEvent.click(menuToggle)

    // Get input field.
    const input = getByTestId('add-more-input')
    const submitButton = getByTestId('add-more-submit-button')

    // Assert that input and submit button are present.
    expect(input).toBeInTheDocument()
    expect(submitButton).toHaveAttribute('disabled')

    // Input new checkbox item.
    fireEvent.change(input, {
      target: {
        value: 'New Checkbox Item!',
      },
    })
github xyfir / illuminsight / web / __tests__ / components / reader / SectionNavigation.spec.tsx View on Github external
expect(() => getByText('Back')).toThrow();

  // Go to next section (last)
  fireEvent.click(getByText('Next'));

  // Validate controls
  getByText('Prev');
  expect(() => getByText('Back')).toThrow();
  expect(() => getByText('Next')).toThrow();

  // Validate TOC not open
  expect(() => getByText('Title')).toThrow();

  // Open TOC and change section (middle)
  fireEvent.click(getByText('TOC'));
  fireEvent.click(getByText('Pride and Prejudice'));
  await waitForDomChange();

  // Validate controls
  getByText('Prev');
  getByText('Back');
  getByText('Next');

  // Validate TOC not open
  expect(() => getByText('Title')).toThrow();

  // Go to previous section (first)
  fireEvent.click(getByText('Prev'));

  // Validate controls
  expect(() => getByText('Prev')).toThrow();
github timc1 / time-capsule / src / components / questionnaire / __tests__ / steps / interests.js View on Github external
// Assert that input and submit button are present.
    expect(input).toBeInTheDocument()
    expect(submitButton).toHaveAttribute('disabled')

    // Input new checkbox item.
    fireEvent.change(input, {
      target: {
        value: 'New Checkbox Item!',
      },
    })

    // Assert that user can now submit
    expect(submitButton).not.toHaveAttribute('disabled')

    fireEvent.click(submitButton)

    // Assert that modal closes after user submits.
    expect(modalToggle).toHaveAttribute('tabindex', '-1')
    expect(input).not.toBeInTheDocument()
    expect(submitButton).not.toBeInTheDocument()

    // TODO: figure out how to test context.questionnaireDispatch so it's not just a mock jest.fn()
  })
})
github bradstiff / react-app-location / tests / integration.js View on Github external
test('navigates from one matched location to another, first uses component prop, second uses render prop', () => {
    const { container, getByText } = renderWithRouter();
    expect(container.innerHTML).toMatch('Home');
    const leftClick = { button: 0 };
    fireEvent.click(getByText(/about/i), leftClick);
    expect(container.innerHTML).toMatch('About');
})
github roginfarrer / react-collapsed / src / __tests__ / collapse.jest.js View on Github external
test('toggle click calls onClick argument with isOpen', () => {
  const onClick = jest.fn();
  const {getByTestId} = render(
    
  );
  const toggle = getByTestId('toggle');

  fireEvent.click(toggle);
  expect(onClick).toHaveBeenCalled();
});
github SeleniumHQ / selenium-ide / packages / selenium-ide-extension / src / neo / __test__ / containers / Console / index.spec.js View on Github external
it('should display an unread log notification when viewing the reference tab)', async () => {
    const { container } = renderIntoDocument()
    const referenceTab = container.querySelector('.reference')
    fireEvent.click(referenceTab)
    await waitForElement(() => container.querySelector('.command-reference'))
    Logger.log('blah')
    const unreadLogNotification = container.querySelector('.log.unread')
    expect(unreadLogNotification).toBeInTheDocument()
  })
})
github lucasconstantino / react-compose-hooks / tests / hooks.spec.js View on Github external
it('should update component when hooks fired', () => {
    const { getByText } = render()

    expect(Counter).toHaveBeenCalledTimes(1)
    fireEvent.click(getByText('Increase'))
    expect(Counter).toHaveBeenCalledTimes(2)

    expect(Counter).toHaveBeenLastCalledWith(withValues({ counter: 1 }), context)
  })
github react-cosmos / react-cosmos / packages / react-cosmos-playground2 / src / plugins / ResponsivePreview / __tests__ / buttonSelectedFixture.tsx View on Github external
it('sets enabled state with stored viewport', async () => {
  registerTestPlugins();
  mockStorage({ [storageKey]: { width: 420, height: 420 } });
  mockRendererCore();

  const { getByText } = loadTestPlugins();
  fireEvent.click(getByText(/responsive/i));

  await wait(() =>
    expect(getResponsivePreviewState()).toEqual({
      enabled: true,
      viewport: { width: 420, height: 420 }
    })
  );
});
github ionic-team / ionic / react / src / components / __tests__ / createComponent.spec.tsx View on Github external
test('should set events on handler', () => {
    const FakeOnClick = jest.fn((e) => e);
    const IonButton = createReactComponent('ion-button');

    const { getByText } = render(
      
        ButtonNameA
      
    );
    fireEvent.click(getByText('ButtonNameA'));
    expect(FakeOnClick).toBeCalledTimes(1);
  });
github ticketmaster / aurora / src / components / Input / __tests__ / CheckBoxGroup.spec.js View on Github external
value="2"
            size="large"
            index={1}
          />
          
        
      
    );

    fireEvent.click(getByTestId("test-checkbox3"));

    expect(getByTestId("test-checkbox").hasAttribute("checked"));
    expect(getByTestId("test-checkbox2").hasAttribute("checked"));
    expect(getByTestId("test-checkbox3").hasAttribute("checked"));
  });
});