Registry / testing / test-keyboard

test-keyboard

JSON →
library2.0.7jsnpmunverified

The `test-keyboard` package provides a programmatic way to compose and dispatch synthetic keyboard events to the DOM, mimicking user typing actions. It is primarily designed for DOM test environments, enabling robust testing of applications that heavily rely on keyboard interactions. This library is part of the broader Remirror ecosystem, though it maintains its own versioning, with the current stable version being 2.0.7. It offers features like batching events for controlled dispatch and simulating OS-specific behaviors (e.g., Mac key modifiers). While the main Remirror packages are in their 3.x series, `test-keyboard` is at 2.x, implying a potentially independent release cadence or a planned future major update to align with Remirror v3.

npm install test-keyboard
INSTALL
IMPORT
SIG · TEST-KEYBOARD
T
test-keyboard
testingjavascriptv2.0.7
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Keyboard
import { Keyboard } from 'test-keyboard';
const Keyboard = require('test-keyboard'); // Incorrect for named export in CJS const Keyboard = require('test-keyboard').default; // No default export
Primary class for creating keyboard event sequences. Named export, so destructuring is required for CommonJS.
KeyboardConstructorParameter
import type { KeyboardConstructorParameter } from 'test-keyboard';
Used for type-checking the constructor parameters when creating a Keyboard instance.
test-keyboard (CJS)
const { Keyboard } = require('test-keyboard');
import { Keyboard } from 'test-keyboard'; // Fails in pure CJS environment
For CommonJS environments (Node.js before ESM support, or older build setups), use destructuring with require().

Demonstrates creating a `Keyboard` instance, composing a sequence of key presses with modifiers, and dispatching them to a target DOM element.

import { Keyboard } from 'test-keyboard'; // Imagine an editor element in your test environment const editorTarget = document.createElement('div'); editorTarget.id = 'editor'; document.body.appendChild(editorTarget); // Create a keyboard instance targeting the editor const keyboard = Keyboard.create({ target: editorTarget, batch: true, // Batch events for controlled dispatch onEventDispatch: (event) => { console.log(`Dispatched event: ${event.type} key='${event.key}'`); }, }); keyboard .start() // Begin event composition .press('h', 'e', 'l', 'l', 'o') // Simulate typing 'hello' .mod({ text: 'Shift-ArrowLeft' }) // Select last character .press('Backspace') // Delete selected character .press('world!') // Type 'world!' .end(); // Dispatch all batched events console.log('Keyboard events dispatched successfully.');
Debug
Known issues
gotchaThe `test-keyboard` package is currently at version `2.x` while the parent `remirror` monorepo has released `3.x` versions for its core packages. This version discrepancy might lead to unexpected behavior or compatibility issues if `test-keyboard` is used within a `remirror@3.x` context that relies on internal `remirror@2.x` APIs, or if `test-keyboard` eventually introduces breaking changes in its own `3.x` release.
fix
Check for a `test-keyboard@3.x` release if using `remirror@3.x` and verify compatibility. For now, ensure your testing environment aligns with the `test-keyboard`'s documented dependencies.
affects: >=2.0.0
gotchaWhen `batch` is set to `true` in `Keyboard.create`, no events will be dispatched until the `.end()` method is explicitly called on the keyboard instance. Forgetting to call `.end()` will result in silently composed but never-fired events.
fix
Always call `.end()` after composing your sequence of actions if `batch: true` is enabled to ensure all events are dispatched.
affects: >=1.0.0
breakingThe `target` property in `KeyboardConstructorParameter` is a required argument. Omitting it will cause a runtime error as the keyboard instance will not know where to dispatch events.
fix
Always provide a valid `Element` to the `target` property when calling `Keyboard.create({ target: yourElement })`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'dispatchEvent')
The `target` element provided to `Keyboard.create` was `null` or `undefined`.
fix
Ensure the `target` property of `KeyboardConstructorParameter` is a valid DOM `Element`.
No keyboard events are being fired in my tests.
You likely enabled `batch: true` in `Keyboard.create` but forgot to call `.end()` after composing the keyboard actions.
fix
Add `.end()` at the end of your keyboard action chain, e.g., `Keyboard.create({...}).start().press('a').end();`
Module not found: Can't resolve 'test-keyboard' in '...' or Cannot find module 'test-keyboard'
The package 'test-keyboard' is not installed or the import path is incorrect for your module system.
fix
Run `npm install test-keyboard` or `yarn add test-keyboard`. Ensure your build configuration correctly handles module resolution, especially between CommonJS and ES Modules.
Upgrade
Version history
2.0.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
test-keyboard — npm install test-keyboard · libregistry