Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: testing-library/user-event
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v13.0.0
Choose a base ref
...
head repository: testing-library/user-event
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v13.0.1
Choose a head ref
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Mar 17, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    fa9299e View commit details
Showing with 23 additions and 2 deletions.
  1. +11 −0 src/__tests__/keyboard/getNextKeyDef.ts
  2. +8 −0 src/__tests__/type.js
  3. +4 −2 src/keyboard/getNextKeyDef.ts
11 changes: 11 additions & 0 deletions src/__tests__/keyboard/getNextKeyDef.ts
Original file line number Diff line number Diff line change
@@ -19,6 +19,16 @@ cases(
key,
code,
}) as keyboardKey,
consumedLength: text.length,
}),
)
expect(getNextKeyDef(`${text}/foo`, options)).toEqual(
expect.objectContaining({
keyDef: expect.objectContaining({
key,
code,
}) as keyboardKey,
consumedLength: text.length,
}),
)
},
@@ -29,6 +39,7 @@ cases(
'unimplemented key': {text: '{Foo}', key: 'Foo', code: 'Unknown'},
'legacy modifier': {text: '{ctrl}', key: 'Control', code: 'ControlLeft'},
'printable character': {text: 'a', key: 'a', code: 'KeyA'},
'modifiers as printable characters': {text: '/', key: '/', code: 'Unknown'},
'{ as printable': {text: '{{', key: '{', code: 'Unknown'},
'[ as printable': {text: '[[', key: '[', code: 'Unknown'},
},
8 changes: 8 additions & 0 deletions src/__tests__/type.js
Original file line number Diff line number Diff line change
@@ -1514,3 +1514,11 @@ test('{enter} fires click on links', () => {
a - keyup: Enter (13)
`)
})

test('type non-alphanumeric characters', () => {
const {element} = setup(`<input/>`)

userEvent.type(element, 'https://test.local')

expect(element).toHaveValue('https://test.local')
})
6 changes: 4 additions & 2 deletions src/keyboard/getNextKeyDef.ts
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ export function getNextKeyDef(
releaseSelf: boolean
} {
const startBracket = ['{', '['].includes(text[0]) ? text[0] : ''
const startModifier = text[1] === '/' ? '/' : ''
const startModifier = startBracket && text[1] === '/' ? '/' : ''

const descriptorStart = startBracket.length + startModifier.length
const descriptor = startBracket
@@ -37,7 +37,9 @@ export function getNextKeyDef(

const descriptorEnd = descriptorStart + descriptor.length
const endModifier =
descriptor !== startBracket && ['/', '>'].includes(text[descriptorEnd])
startBracket &&
descriptor !== startBracket &&
['/', '>'].includes(text[descriptorEnd])
? text[descriptorEnd]
: ''