How to use the react-testing-library.fireEvent.keyDown 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 mlaursen / react-md / packages / wia-aria / src_old / hooks / __tests__ / useSearchEventHandler.tsx View on Github external
it("should call the onKeyboardFocus with the correct values when there is a match", () => {
      const { container } = render();
      const items = container.querySelectorAll("[role='menuitem']");
      fireEvent.keyDown(items[0], { key: "I" });

      expect(onKeyboardFocus).toBeCalledWith(
        expect.objectContaining({
          element: items[1],
          elementIndex: 1,
          // using items causes a memeory leak for some reason
          focusableElements: expect.any(Array),
        }),
        expect.any(Object)
      );

      fireEvent.keyDown(items[1], { key: "t" });
      expect(onKeyboardFocus).toBeCalledWith(
        expect.objectContaining({
          element: items[2],
          elementIndex: 2,
          focusableElements: expect.any(Array),
        }),
        expect.any(Object)
      );
    });
  });
github ticketmaster / aurora / src / components / Backdrop / __tests__ / index.spec.js View on Github external
it("calls the onRequestClose callback on pressing the ESC key", () => {
    const closeSpy = jest.fn();

    render(
      
        <div>Component under test</div>
      
    );

    fireEvent.keyDown(global.document, {
      keyCode: ESCAPE
    });

    expect(closeSpy).toHaveBeenCalled();
  });
github mlaursen / react-md / packages / wia-aria / src_old / hooks / __tests__ / useSearchEventHandler.tsx View on Github external
it("should not call the onKeyboardFocus when the key has a length greater than 1", () =&gt; {
      const { getByRole } = render();
      const menu = getByRole("menu");
      fireEvent.keyDown(menu, { key: "Unidentified" });
      progress();

      fireEvent.keyDown(menu, { key: "Tab" });
      progress();

      fireEvent.keyDown(menu, { key: "Home" });
      progress();

      fireEvent.keyDown(menu, { key: "Shift" });
      progress();

      fireEvent.keyDown(menu, { key: "Alt" });
      progress();

      fireEvent.keyDown(menu, { key: "Option" });
      progress();

      fireEvent.keyDown(menu, { key: "Enter" });
      progress();
github mlaursen / react-md / packages / wia-aria / src_old / hooks / __tests__ / useKeyboardFocus.tsx View on Github external
it("should not trigger the onKeyboardFocus when there is not a valid keyboard key mapping", () =&gt; {
    const { getByRole } = render(
      
    );
    const menu = getByRole("menu");
    fireEvent.keyDown(menu);
    fireEvent.keyDown(menu, { key: "Tab" });
    fireEvent.keyDown(menu, { key: "Tab", shiftKey: true });
    expect(onKeyboardFocus).not.toBeCalled();
  });
});
github ticketmaster / aurora / src / components / List / __tests__ / Backdrop.spec.js View on Github external
it("do not calls the onKeyPress function on pressing any other key than ESC", () =&gt; {
    const { container } = render(
      
        
          <div>Europe</div>
          <div>Africa</div>
          <div>Asias</div>
        
      
    );

    fireEvent.keyDown(global.document, {
      key: " ",
      keyCode: 32
    });

    expect(container.firstChild).toMatchSnapshot();
  });
github mlaursen / react-md / packages / wia-aria / src_old / hooks / __tests__ / useSearchEventHandler.tsx View on Github external
it("should call the prop onKeyDown", () =&gt; {
      const onKeyDown = jest.fn();

      const { getByRole } = render();
      fireEvent.keyDown(getByRole("menu"));
      jest.runAllTimers();
      expect(onKeyDown).toBeCalled();
    });
github draft-js-plugins / next / examples / image-example / src / __test__ / index.js View on Github external
it('Image should be deleted', async () => {
    fireEvent.keyDown(clickedImage, { key: 'Backspace', code: 8})
    await wait(() => expect(container.querySelector('img')).should.be.empty)
  })
})
github flow-typed / flow-typed / definitions / npm / react-testing-library_v5.x.x / flow_v0.67.1- / test_react-testing-library_v5.x.x.js View on Github external
it('should expose fire event helpers', () => {
    fireEvent.copy(htmlEl);
    fireEvent.cut(htmlEl);
    fireEvent.paste(htmlEl);
    fireEvent.compositionEnd(htmlEl);
    fireEvent.compositionStart(htmlEl);
    fireEvent.compositionUpdate(htmlEl);
    fireEvent.keyDown(htmlEl);
    fireEvent.keyPress(htmlEl);
    fireEvent.keyUp(htmlEl);
    fireEvent.focus(htmlEl);
    fireEvent.blur(htmlEl);
    fireEvent.change(htmlEl);
    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);
github ticketmaster / aurora / src / components / Input / __tests__ / DropDownGroup.spec.js View on Github external
it("if entered texted doesn't not match then select the option that matched previously", () => {
    const onChange = jest.fn();
    const { queryAllByText, getByTestId } = renderTestComponentOne({
      onChange
    });

    fireEvent.keyDown(getByTestId("test-dropContainer"), {
      key: "ArrowDown",
      keyCode: 40,
      which: 40,
      bubbles: true
    });

    fireEvent.keyDown(getByTestId("test-dropDownOptionOne"), {
      key: "s",
      keyCode: 83,
      which: 83,
      bubbles: true
    });

    fireEvent.keyDown(getByTestId("test-dropDownOptionOne"), {
      key: "z",
      keyCode: 90,
      which: 90,
      bubbles: true
    });

    fireEvent.keyDown(getByTestId("test-dropDownOptionOne"), {
      key: "",
      keyCode: 32,
github acl-services / paprika / packages / SidePanel / SidePanel.spec.js View on Github external
it("should triggered onClose when pressing ESC key", () =&gt; {
    const fn = jest.fn();
    const { getByRole } = render({
      onClose: fn,
      children: Header,
    });

    fireEvent.keyDown(getByRole("dialog"), { key: "Escape", keyCode: 27, which: 27 });

    expect(fn).toHaveBeenCalled();
  });