Open ienzam opened 4 years ago
Is this possibly related to the bug I've been seeing here: https://github.com/angular/components/issues/18984 ? Where typing in a contenteditable div doesn't do anything (and mine just happens to be from the JSONEditor)?
Any news?
Late to the party, but got into this thread while looking for solution to fix unit tests for myself - I will share my workaround.
I see that the typeInElement
function (which is used internally when sendKeys
method is called) does check if the element is an input
or textarea
. If so it sets its value
property to whatever is passed as parameter to sendKeys
. Otherwise it doesn't set any content. Beside that sendKeys
dispatch the events: keydown
, keypress
and keyup
.
So the work around is to call sendKeys
together with setContenteditableValue
.
This is how I solve it in my harness:
private contentEditableDivLocator = this.locatorFor('div[contenteditable="true"');
async getContentEditable(): Promise<TestElement> {
return await this.contentEditableDivLocator();
}
async typeText(text: string): Promise<void> {
const contentEditableTestElement = await this.getContentEditable();
contentEditableTestElement.setContenteditableValue &&
(await contentEditableTestElement.setContenteditableValue(text));
await contentEditableTestElement.sendKeys(text);
}
Note:
setContenteditableValue
is possibly undefined, so need to do this ugly checksendKeys
as it dispatches events. That way we mock real browser behavior the most.
Reproduction
This is a issue with TestHarness, don't know how I can reproduce it with StackBlitz.
Steps to reproduce:
<div contenteditable="true></div>
.sendKeys()
to that div via harness.Expected Behavior
The
div
will show updated text.Actual Behavior
<div>
remains the same.Environment