Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

test-keyboard

Package Overview
Dependencies
Maintainers
0
Versions
263
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

test-keyboard

A test keyboard for composing fake keyboard events

  • 2.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.9K
decreased by-7.88%
Maintainers
0
Weekly downloads
 
Created
Source

test-keyboard

npm

A test keyboard for dispatching events to the dom which mimics keyboard actions from the user.

The problem

You want to write tests for code that makes heavy usage of the keyboard and you're finding it hard to compose these keyboard events together.

This solution

test-keyboard is an elegant way of composing keyboard events together as if a user was typing.

It is primarily designed for dom-test environments but could be extracted out into something that can be used in your front-end code.

Installation

yarn add test-keyboard # yarn
pnpm add test-keyboard # pnpm
npm install test-keyboard # npm

Keyboard.create - (params: KeyboardConstructorParameter) => Keyboard

import { Keyboard } from 'test-keyboard';

const target = document.querySelector('#editor');
Keyboard.create({
  target,
})
  .start() // Allows events to be dispatched
  .mod({ text: 'Ctrl-Shift-Enter' })
  .end(); // Dispatches al the events.

KeyboardConstructorParameter

PropertyTypeDefaultDescription
targetElementREQUIREDThe target of our events.
defaultOptionsKeyboardEventInit{}The target of our events.
isMacbooleanfalseWhether to simulate a mac.
batchbooleanfalseWhether to wait until end is called before running all accumulated actions.
onEventDispatch(event: KeyboardEvent) => void() => {}Called whenever an event is dispatched with the keyboard event as a parameter.

Acknowledgements

  • Puppeteer for providing the US Keyboard information.

Keywords

FAQs

Package last updated on 30 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc