Skip to content

userEvent.type - issue when using {Alt>}{Enter}{/Alt} #912

@xDisfigure

Description

@xDisfigure

Reproduction example

https://codesandbox.io/s/happy-ritchie-tq2fbg?file=/src/App.test.tsx

edit: https://codesandbox.io/s/clever-sea-ocux0n?file=/src/App.js

Prerequisites

Have a textarea which handles new line by holding "alt" and pressing "enter"

Expected behavior

In the test, for the second scenario (alt + enter) I would expect to see the new line added to the textarea value.

const sentence1 = 'here im the first sentence.';
const sentence2 = 'i should be after a new line.';
await userEvent.type(input, `${sentence1}{Alt>}{Enter}{/Alt}${sentence2}`)
expect(input).toHaveValue(`${sentence1}\n${sentence2}`) // it should not fail

Expected text result

here im the first sentence.
i should be after a new line.

Actual behavior

To make a newline inside the textarea you should be able to manually :

  1. Hold "shift" and then press "enter"
  2. Hold "alt" and then press "enter"

Now if you run the test suites you can see that the test asserting the second scenario (alt+enter) will fail.

const sentence1 = 'here im the first sentence.';
const sentence2 = 'i should be after a new line.';
await userEvent.type(input, `${sentence1}{Alt>}{Enter}{/Alt}${sentence2}`)
expect(input).toHaveValue(`${sentence1}\n${sentence2}`) // this fails

The new line is not appended. Im getting the following text as the textarea value:

here im the first sentence.i should be after a new line.

User-event version

14.0.4

Environment

Testing Library framework: @testing-library/[email protected]

JS framework: [email protected]
Test environment: [email protected]
DOM implementation: [email protected]

Additional context

The test was working on [email protected], it seems to fail since we migrate to the 14.0.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreleased

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions