Skip to content

Commit

Permalink
fix #1824: trigger keyboard event regression (#1826)
Browse files Browse the repository at this point in the history
* fix(dom-event): fix key override in trigger events

fix #1824

* test(dom-event): test for trigger events with keys
  • Loading branch information
Ana Margarida Silva authored Apr 21, 2021
1 parent 7413b37 commit b755c3a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/test-utils/src/create-dom-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function getOptions(eventParams) {
// Any derived options should go here
keyCode,
code: keyCode,
key
key: key || options.key
}
}

Expand Down
15 changes: 15 additions & 0 deletions test/specs/wrapper/trigger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ describeWithShallowAndMount('trigger', mountingMethod => {
})
})

describe('causes keydown handler to fire with the appropriate key when wrapper.trigger("keydown", { key: "k" }) is fired on a Component', async () => {
const keydownHandler = jest.fn()
const wrapper = mountingMethod(ComponentWithEvents, {
propsData: { keydownHandler }
})

await wrapper.find('.keydown').trigger('keydown', { key: 'k' })

const keyboardEvent = keydownHandler.mock.calls[0][0]

it('contains the key', () => {
expect(keyboardEvent.key).toEqual('k')
})
})

it('causes keydown handler to fire when wrapper.trigger("keydown.enter") is fired on a Component', async () => {
const keydownHandler = jest.fn()
const wrapper = mountingMethod(ComponentWithEvents, {
Expand Down

0 comments on commit b755c3a

Please sign in to comment.