How to use the @testing-library/react.fireEvent 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 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
it('should throw on invalid arguments', () => {
    // $ExpectError
    fireEvent(1);
    // $ExpectError
    fireEvent(htmlEl, 1);
  });
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
it('should throw on invalid arguments', () => {
    // $ExpectError
    fireEvent(1);
    // $ExpectError
    fireEvent(htmlEl, 1);
  });
github atlassian / react-beautiful-dnd / test / unit / integration / droppable / placeholder.spec.js View on Github external
// foreign placeholder is now gone
      expect(hasPlaceholder(preset.foreign.descriptor.id, container)).toBe(
        false,
      );
      // home placeholder is still around and will now animate closed
      expect(hasPlaceholder(preset.home.descriptor.id, container)).toBe(true);

      // placeholder is now collapsing
      const placeholder: HTMLElement = getPlaceholder(
        preset.home.descriptor.id,
        container,
      );
      expect(placeholder.style.height).toBe('0px');

      // faking a transition end
      fireEvent(placeholder, getTransitionEnd('height'));

      // placeholder is gone
      expect(hasPlaceholder(preset.home.descriptor.id, container)).toBe(false);
    });
  });
github atlassian / react-beautiful-dnd / test / unit / integration / drag-handle / sensor-marshal / click-blocking.spec.js View on Github external
,
  );
  const handle: HTMLElement = getByText('item: 0');
  invariant(api);

  // trigger a drop
  const preDrag: ?PreDragActions = api.tryGetLock('0');
  invariant(preDrag);
  const drag: SnapDragActions = preDrag.snapLift();
  act(() => drag.drop({ shouldBlockNextClick: true }));

  // fire click
  const first: MouseEvent = createEvent.click(handle);
  const second: MouseEvent = createEvent.click(handle);
  fireEvent(handle, first);
  fireEvent(handle, second);

  // only first click is prevented
  expect(first.defaultPrevented).toBe(true);
  expect(second.defaultPrevented).toBe(false);
});
github react-dropzone / react-dropzone / src / index.spec.js View on Github external
it('permits drags and drops on elements inside our dropzone', () => {
      const { container } = render(
        
          {({ getRootProps, getInputProps }) => (
            <div>
              <input>
            </div>
          )}
        
      )
      const dropzone = container.querySelector('div')

      const dropEvt = new Event('drop', { bubbles: true })
      const dropEvtPreventDefaultSpy = jest.spyOn(dropEvt, 'preventDefault')

      fireEvent(dropzone, dropEvt)
      // A call is from the onDrop handler for the dropzone,
      // but there should be no more than 1
      expect(dropEvtPreventDefaultSpy).toHaveBeenCalled()
    })
github atlassian / react-beautiful-dnd / test / unit / integration / drag-handle / mouse-sensor / starting-a-dragging.spec.js View on Github external
it('should allow standard click events', () =&gt; {
  const { getByText } = render();
  const handle: HTMLElement = getByText('item: 0');

  const click: MouseEvent = createEvent.click(handle);
  fireEvent(handle, click);

  expect(click.defaultPrevented).toBe(false);
});
github atlassian / react-beautiful-dnd / test / unit / integration / drag-handle / mouse-sensor / starting-a-dragging.spec.js View on Github external
it('should not start a drag if not using the primary mouse button', () =&gt; {
  const { getByText } = render();
  const handle: HTMLElement = getByText('item: 0');

  const mouseDown: Event = createEvent.mouseDown(handle, {
    button: primaryButton + 1,
  });
  fireEvent(handle, mouseDown);
  fireEvent.mouseMove(handle, {
    clientX: 0,
    clientY: sloppyClickThreshold,
  });

  expect(isDragging(handle)).toBe(false);
});
github atlassian / react-beautiful-dnd / test / unit / integration / drag-handle / touch-sensor / stopping-a-drag.spec.js View on Github external
it('should prevent default on an escape press', () =&gt; {
  const onDragEnd = jest.fn();
  const { getByText } = render();
  const handle: HTMLElement = getByText('item: 0');

  simpleLift(touch, handle);

  const event: Event = createEvent.keyDown(handle, {
    keyCode: keyCodes.escape,
  });
  fireEvent(handle, event);

  expect(event.defaultPrevented).toBe(true);
  expect(getDropReason(onDragEnd)).toBe('CANCEL');
});
github atlassian / react-beautiful-dnd / test / unit / integration / drag-handle / mouse-sensor / starting-a-dragging.spec.js View on Github external
it('should call preventDefault on the initial mousedown event to prevent the element gaining focus', () =&gt; {
  const { getByText } = render();
  const handle: HTMLElement = getByText('item: 0');

  const mouseDown: MouseEvent = createEvent.mouseDown(handle);
  fireEvent(handle, mouseDown);

  expect(mouseDown.defaultPrevented).toBe(true);
});
github zendeskgarden / react-containers / packages / keyboardfocus / src / KeyboardFocusContainer.spec.tsx View on Github external
it('should not apply focused prop if pointerdown is triggered', () =&gt; {
        const { getByTestId } = render();
        const trigger = getByTestId('trigger');

        fireEvent(trigger, new MouseEvent('pointerdown'));
        jest.runOnlyPendingTimers();

        expect(trigger).toHaveAttribute('data-focused', 'false');
      });
    });