{"id":14113,"library":"test-keyboard","title":"Test Keyboard Event Composer","description":"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.","status":"active","version":"2.0.7","language":"javascript","source_language":"en","source_url":"https://github.com/remirror/remirror","tags":["javascript","compose events","events","keyboard","typescript"],"install":[{"cmd":"npm install test-keyboard","lang":"bash","label":"npm"},{"cmd":"yarn add test-keyboard","lang":"bash","label":"yarn"},{"cmd":"pnpm add test-keyboard","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primary class for creating keyboard event sequences. Named export, so destructuring is required for CommonJS.","wrong":"const Keyboard = require('test-keyboard'); // Incorrect for named export in CJS\nconst Keyboard = require('test-keyboard').default; // No default export","symbol":"Keyboard","correct":"import { Keyboard } from 'test-keyboard';"},{"note":"Used for type-checking the constructor parameters when creating a Keyboard instance.","symbol":"KeyboardConstructorParameter","correct":"import type { KeyboardConstructorParameter } from 'test-keyboard';"},{"note":"For CommonJS environments (Node.js before ESM support, or older build setups), use destructuring with require().","wrong":"import { Keyboard } from 'test-keyboard'; // Fails in pure CJS environment","symbol":"test-keyboard (CJS)","correct":"const { Keyboard } = require('test-keyboard');"}],"quickstart":{"code":"import { Keyboard } from 'test-keyboard';\n\n// Imagine an editor element in your test environment\nconst editorTarget = document.createElement('div');\neditorTarget.id = 'editor';\ndocument.body.appendChild(editorTarget);\n\n// Create a keyboard instance targeting the editor\nconst keyboard = Keyboard.create({\n  target: editorTarget,\n  batch: true, // Batch events for controlled dispatch\n  onEventDispatch: (event) => {\n    console.log(`Dispatched event: ${event.type} key='${event.key}'`);\n  },\n});\n\nkeyboard\n  .start() // Begin event composition\n  .press('h', 'e', 'l', 'l', 'o') // Simulate typing 'hello'\n  .mod({ text: 'Shift-ArrowLeft' }) // Select last character\n  .press('Backspace') // Delete selected character\n  .press('world!') // Type 'world!'\n  .end(); // Dispatch all batched events\n\nconsole.log('Keyboard events dispatched successfully.');","lang":"typescript","description":"Demonstrates creating a `Keyboard` instance, composing a sequence of key presses with modifiers, and dispatching them to a target DOM element."},"warnings":[{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Always call `.end()` after composing your sequence of actions if `batch: true` is enabled to ensure all events are dispatched.","message":"When `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always provide a valid `Element` to the `target` property when calling `Keyboard.create({ target: yourElement })`.","message":"The `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.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2':104 '2.0.7':68 '3':96 'action':27 'align':119 'applic':40 'batch':73 'behavior':83 'broader':53 'cadenc':111 'compos':4,15,124 'control':76 'current':64 'design':31 'dispatch':17,77 'dom':23,33 'e.g':84 'ecosystem':55 'enabl':36 'environ':35 'event':3,20,74,125,126 'featur':71 'futur':115 'heavili':42 'impli':106 'independ':109 'interact':46 'javascript':123 'key':86 'keyboard':2,8,19,45,101,127 'librari':48 'like':72 'mac':85 'main':90 'maintain':58 'major':116 'mimick':24 'modifi':87 'offer':70 'os':81 'os-specif':80 'packag':9,92 'part':50 'plan':114 'potenti':108 'primarili':30 'programmat':12 'provid':10 'releas':110 'reli':43 'remirror':54,91,121 'robust':37 'seri':98 'simul':79 'specif':82 'stabl':65 'synthet':18 'test':1,7,34,38,100 'test-keyboard':6,99 'though':56 'type':26 'typescript':128 'updat':117 'user':25 'v3':122 'version':61,66 'way':13 'x':97,105","created_at":"2026-04-20T01:58:00.248165+00:00","updated_at":"2026-04-20T01:58:00.248165+00:00","problems":[{"fix":"Ensure the `target` property of `KeyboardConstructorParameter` is a valid DOM `Element`.","cause":"The `target` element provided to `Keyboard.create` was `null` or `undefined`.","error":"TypeError: Cannot read properties of undefined (reading 'dispatchEvent')"},{"fix":"Add `.end()` at the end of your keyboard action chain, e.g., `Keyboard.create({...}).start().press('a').end();`","cause":"You likely enabled `batch: true` in `Keyboard.create` but forgot to call `.end()` after composing the keyboard actions.","error":"No keyboard events are being fired in my tests."},{"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.","cause":"The package 'test-keyboard' is not installed or the import path is incorrect for your module system.","error":"Module not found: Can't resolve 'test-keyboard' in '...' or Cannot find module 'test-keyboard'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/remirror/remirror","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/test-keyboard","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}