Skip to content

Commit

Permalink
Add test for key remap
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertWHurst committed Jul 26, 2023
1 parent 23a5a63 commit 74799f4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 0 additions & 2 deletions packages/keystrokes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@
"eslint": "^8.45.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^5.0.0",
"node-static": "^0.7.11",
"prettier": "^3.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.1.6",
"vite": "^4.4.6",
"vitest": "^0.33.0"
Expand Down
27 changes: 27 additions & 0 deletions packages/keystrokes/src/tests/keystrokes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,33 @@ describe('new Keystrokes(options)', () => {
expect(aPressed).toBeCalledTimes(1)
expect(aReleased).toBeCalledTimes(1)
})

it('can setup key remaps', () => {
const keystrokes = createTestKeystrokes()

keystrokes.bindEnvironment({
keyRemap: {
a: 'b',
b: 'c',
},
})

const aPressed = vi.fn()
const bPressed = vi.fn()
const cPressed = vi.fn()

keystrokes.bindKey('a', aPressed)
keystrokes.bindKey('b', bPressed)
keystrokes.bindKey('c', cPressed)

keystrokes.press({ key: 'a' })
keystrokes.press({ key: 'b' })
keystrokes.press({ key: 'c' })

expect(aPressed).toBeCalledTimes(0)
expect(bPressed).toBeCalledTimes(1)
expect(cPressed).toBeCalledTimes(2)
})
})

describe('#bindKey(keyCombo, handler)', () => {
Expand Down

0 comments on commit 74799f4

Please sign in to comment.