How to use the @testing-library/react.fireEvent.mouseDown function in @testing-library/react

To help you get started, we’ve selected a few @testing-library/react 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 atlassian / react-beautiful-dnd / test / unit / integration / drag-handle / mouse-sensor / cancel-while-pending.spec.js View on Github external
it('should abort when there is a window scroll', () => {
  const { getByText } = render();
  const handle: HTMLElement = getByText('item: 0');

  fireEvent.mouseDown(handle);

  // abort
  const event: Event = new Event('scroll', {
    target: window,
    bubbles: true,
    cancelable: true,
  });
  fireEvent(window, event);

  // would normally start
  fireEvent.mouseMove(handle, {
    clientX: 0,
    clientY: sloppyClickThreshold,
  });

  // event not consumed as it is an indirect cancel
github downshift-js / downshift / src / __tests__ / portal-support.js View on Github external
{isOpen ?  : null}
          
        )}
      
    )
  }
  const {getByTestId, queryByTestId} = render()
  expect(queryByTestId('menu')).toBeNull()
  getByTestId('button').click()
  expect(getByTestId('menu')).toBeInstanceOf(HTMLElement)

  const notAnItem = getByTestId('not-an-item')

  // Mouse events
  fireEvent.mouseDown(notAnItem)
  notAnItem.focus() // sets document.activeElement
  fireEvent.mouseUp(notAnItem)
  expect(getByTestId('menu')).toBeInstanceOf(HTMLElement)

  // Touch events
  fireEvent.touchStart(notAnItem)
  fireEvent.touchEnd(notAnItem)
  notAnItem.focus() // sets document.activeElement
  expect(getByTestId('menu')).toBeInstanceOf(HTMLElement)

  getByTestId('item').click()
  expect(queryByTestId('menu')).toBeNull()
  expect(getByTestId('selection')).toHaveTextContent('The item')
})
github Synerise / synerise-design / packages / components / input-number / src / __specs__ / InputNumber.spec.tsx View on Github external
it('should keep min value', () => {
    // ARRANGE
    const TEST_ID = 'test-id';
    const { getByTestId } = renderWithProvider(
      
    );
    const input = getByTestId(TEST_ID) as HTMLInputElement;

    // ACT
    fireEvent.mouseDown(document.getElementsByClassName('ant-input-number-handler-down')[0]);

    // ASSERT
    expect(input.value).toEqual('2');
  });
github flow-typed / flow-typed / definitions / npm / @testing-library / react_v8.x.x / flow_v0.104.x- / test_react_v8.x.x.js View on Github external
fireEvent.input(htmlEl);
    fireEvent.invalid(htmlEl);
    fireEvent.submit(htmlEl);
    fireEvent.click(htmlEl);
    fireEvent.contextMenu(htmlEl);
    fireEvent.dblClick(htmlEl);
    fireEvent.doubleClick(htmlEl);
    fireEvent.drag(htmlEl);
    fireEvent.dragEnd(htmlEl);
    fireEvent.dragEnter(htmlEl);
    fireEvent.dragExit(htmlEl);
    fireEvent.dragLeave(htmlEl);
    fireEvent.dragOver(htmlEl);
    fireEvent.dragStart(htmlEl);
    fireEvent.drop(htmlEl);
    fireEvent.mouseDown(htmlEl);
    fireEvent.mouseEnter(htmlEl);
    fireEvent.mouseLeave(htmlEl);
    fireEvent.mouseMove(htmlEl);
    fireEvent.mouseOut(htmlEl);
    fireEvent.mouseOver(htmlEl);
    fireEvent.mouseUp(htmlEl);
    fireEvent.select(htmlEl);
    fireEvent.touchCancel(htmlEl);
    fireEvent.touchEnd(htmlEl);
    fireEvent.touchMove(htmlEl);
    fireEvent.touchStart(htmlEl);
    fireEvent.scroll(htmlEl);
    fireEvent.wheel(htmlEl);
    fireEvent.abort(htmlEl);
    fireEvent.canPlay(htmlEl);
    fireEvent.canPlayThrough(htmlEl);
github albizures / react-dynamic-layout / src / components / Float / __tests__ / index.spec.tsx View on Github external
it('should follow the mouse until is dropped', () => {
      const onClose = jest.fn();
      const { container } = getQueries({
        dragbar: ,
      });

      const dragbar = container.getElementsByClassName(
        'rdl-float__drag-bar',
      )[0];

      fireEvent.mouseDown(dragbar, { clientX: 10, clientY: 10 });
      fireEvent.mouseMove(window, { clientX: 11, clientY: 11 });

      expect(container).toHaveStyle(`
        top: 1px;
        left: 1px;
      `);

      fireEvent.mouseMove(window, { clientX: 20, clientY: 20 });

      expect(container).toHaveStyle(`
        top: 10px;
        left: 10px;
      `);

      fireEvent.mouseUp(window, { clientX: 20, clientY: 20 });
github downshift-js / downshift / src / __tests__ / downshift.props.js View on Github external
function mouseDownAndUp(node) {
  fireEvent.mouseDown(node)
  fireEvent.mouseUp(node)
}
github netlify / netlify-cms / packages / netlify-cms-widget-select / src / __tests__ / select.spec.js View on Github external
function clickClearButton(container) {
  const allSvgs = container.querySelectorAll('svg');
  const clear = allSvgs[allSvgs.length - 2];

  fireEvent.mouseDown(clear, {
    button: 0,
  });
}
github downshift-js / downshift / src / __tests__ / downshift.get-item-props.js View on Github external
const childrenSpy = jest.fn(({getItemProps}) => (
    <div>
      <button data-testid="external-button">
      <div>
        </div></button><button data-testid="in-item-button">
      </button></div>
    
  ))
  const {queryByTestId} = render({childrenSpy})
  const externalButton = queryByTestId('external-button')
  const inItemButton = queryByTestId('in-item-button')
  childrenSpy.mockClear()

  externalButton.focus()
  expect(document.activeElement).toBe(externalButton)
  fireEvent.mouseDown(inItemButton)
  expect(document.activeElement).toBe(externalButton)
})
github zendeskgarden / react-containers / packages / focusvisible / src / FocusVisibleContainer.spec.tsx View on Github external
it('does not apply focus treatment if pointer is used', () =&gt; {
    const { getByTestId } = render();
    const button = getByTestId('button');

    fireEvent.mouseDown(button);
    fireEvent.focus(button);

    expect(button).not.toHaveAttribute('data-garden-focus-visible');
  });