I have an LWC that updloads a file:
<lightning-input type="file" label={label.AttachInvoice} accept="image/png, image/jpg, image/gif, application/pdf" onchange={invoiceUploadHandler}></lightning-input>
Question: How do you set up a JEST test for this onchange handler? Where do you inject a test file?
Adding my handler:
invoiceUploadHandler(event) {
let theFile = event.target.files[0];
let reader = new FileReader();
let temp = this;
reader.onload = function() {
let theContents = this.result.split(/,/)[1];
temp.invoiceUploads = temp.invoiceUploads.slice();
temp.invoiceUploads.push('Carrier Invoice');
doUploadFile({ loadId: temp.recordId, filename: 'Carrier Invoice', contentType: theFile.type, contents: theContents })
.then(result => {
LightningUtil.processMessagesAndErrors2(temp, result);
})
.catch(error => {
LightningUtil.logError(temp, error);
});
}
reader.readAsDataURL(theFile);
}
Thanks.