Repository navigation
feat: allow setValue to set values to contenteditable divs - #2671
Tardigrada777 wants to merge 1 commit into
Conversation
✅ Deploy Preview for vue-test-utils-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| this.trigger('input') | ||
| // trigger `change` for `v-model.lazy` | ||
| return this.trigger('change') | ||
| } else if (tagName === 'DIV' && this.attributes().contenteditable) { |
There was a problem hiding this comment.
AFAIK contenteditable is available on all tags, not only on divs
and the presence of the attribute might not be enough, as I think in <div contenteditable="true"><div id="inner"></div></div>, #inner is also editable.
I think using the property isContentEditable might be more reliable
| expect(onInput).toHaveBeenCalledTimes(1) | ||
| expect(onChange).toHaveBeenCalledTimes(1) | ||
| }) | ||
| }) |
There was a problem hiding this comment.
It would be great to have more tests, with other elements than div, other values than true, nested elements with parents that are editable or not, etc.
|
@Tardigrada777 Do you still want to work on this or should we close it? |
|
@Tardigrada777 Is this something you are still interested in landing? |
|
@Tardigrada777 are you still planning to finish this PR? If not, I'd be happy to pick it up and address the review comments. |
|
Opened #3033 that builds on this and addresses the review here. |
|
Superseded by #3033 |
Implements #2390
Support
setValueforcontenteditableElementsSummary
This PR extends the
DOMWrapper.setValuemethod to support elements with thecontenteditableattribute (such as<div contenteditable="true">). Previously,setValuewas only applicable to form inputs, textareas, and selects. With this change, users can now easily set the inner HTML of contenteditable elements in their tests, and trigger the expectedinputandchangeevents.Details
setValue:When called on a
DIVwith thecontenteditableattribute,setValueupdates the element’sinnerHTML, triggers bothinputandchangeevents, and supports any value (object values will be stringified).If
setValueis called on an unsupported element, an error is still thrown as before.Added a dedicated test case to verify that
setValueproperly updates a contenteditable element’s inner HTML and triggers the appropriate events.Motivation
Rich text editors and other contenteditable-based components are common in modern web apps. This enhancement allows for more robust and expressive testing of these components, improving DX and test reliability.
Example Usage