Description
Feature Description
I would like to see a method on TestElement
that allows for setting properties on the underlying element. Specifically, for setting the files
property on an input
element.
Use Case
I am creating a feature for an app to allow users to change their profile picture (avatar). This feature is similar to the one on Google Accounts (shown below).
I ran into a problem trying to create a ComponentHarness
that would allow me to simulate the change
event on the underlying input
element with a list of files. The files
need to be set on the underlying input
element before dispatching a change event. There is currently no way to set properties on the underlying element before dispatching the event. Currently since I am only using the ComponentHarness
for unit tests I simple cast the TestElement
.
async setFiles(files: File[]) {
const input = await this._input();
if (files && input instanceof UnitTestElement) {
Object.defineProperty((input as UnitTestElement).element, 'files', {
configurable: true,
enumerable: true,
writable: true,
value: files,
});
}
input.dispatchEvent('change');
}
The other way to do this, AFAIK is to extend TestElement
and TestBedHarnessEnvironment
to return the extended TestElement
.
I am not sure if creating a generic setProperties
method on TestElement
similar to being able to set EventData
on events is the way to go or if a specific setInputFiles
similar to setInputValue
should be added.