Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support contenteditable divs with userEvent.paste #699

Closed
rbrady-hs opened this issue Jul 15, 2021 · 3 comments · Fixed by #785
Closed

Support contenteditable divs with userEvent.paste #699

rbrady-hs opened this issue Jul 15, 2021 · 3 comments · Fixed by #785
Labels
enhancement New feature or request
Milestone

Comments

@rbrady-hs
Copy link

  • @testing-library/user-event version: 13.1.9
  • Testing Framework and version: jasmine 2.91
  • DOM Environment: Chrome 91.0.4472.114

Relevant code or config

describe('contentEditable', () => {
  it('pastes', () => {
    render(<div contentEditable="true" data-testid="input" />);
    userEvent.paste(screen.getByTestId('input'), 'asd');
    expect(screen.getByLabelText('input').value).toEqual('asd');
  });
});

What you did:

As above, tried pasting into a div with contenteditable="true"

What happened:

Test fails with the following error message:

TypeError: The given DIV element is currently unsupported.
      A PR extending this implementation would be very much welcome at https://github.com/testing-library/user-event

Reproduction repository: N/A

Problem description: N/A

Suggested solution: Not too sure what the implementation would look like, but couldn't find a feature request covering this so thought I'd add an issue if that's alright!

@ph-fritsche ph-fritsche added the enhancement New feature or request label Jul 17, 2021
@signal-intrusion
Copy link

signal-intrusion commented Oct 27, 2021

This would be fantastic. We have some custom paste behaviors that cannot be tested in Jest currently.

There is a sanity check here:

user-event/src/paste.ts

Lines 36 to 41 in a31ecc9

if (!isSupportedElement(element)) {
throw new TypeError(
`The given ${element.tagName} element is currently unsupported.
A PR extending this implementation would be very much welcome at https://github.com/testing-library/user-event`,
)
}

and here:

user-event/src/paste.ts

Lines 17 to 27 in a31ecc9

function isSupportedElement(
element: HTMLElement,
): element is
| HTMLTextAreaElement
| (HTMLInputElement & {type: editableInputTypes}) {
return (
(isElementType(element, 'input') &&
Boolean(editableInputTypes[element.type as editableInputTypes])) ||
isElementType(element, 'textarea')
)
}

which should also check for contenteditable attr on just about any element.

@ph-fritsche ph-fritsche added this to the userEvent v14 milestone Nov 15, 2021
@ph-fritsche
Copy link
Member

Please have a look at #782 .

@ph-fritsche ph-fritsche linked a pull request Nov 17, 2021 that will close this issue
3 tasks
@ph-fritsche
Copy link
Member

Resolved in #785

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants