I have a LWC Component which is used for record upload process.
Below is my LWC Javascript code:
import { LightningElement, api } from 'lwc';
import file1 from '@salesforce/apex/customLwcController.file1';
import file2 from '@salesforce/apex/customLwcController.file2';
export default class customRecordProcess extends LightningElement {
@api customRecordId;
fileName = null;
customFileId = null;
showModalButton = false;
modalButtonLabel = '';
showFileName = false;
customFileIds = [];
isModalOpen = false;
onUploadComplete(file, result) {
console.log('onUploadComplete');
this.customFileIds.push({Id: result, Title: file.name});
if (this.fileName === null) {
this.fileName = file.name;
this.customFileId = result;
}
this.updateDisplayText();
}
handleFileUpload(event){
let file = event.target.files[0];
let reader = new customReader();
file.sObject
}
}
Below is my HTML Code:
<template>
<div class="slds-grid">
<lightning-formatted-text class="left-col" value=""></lightning-formatted-text>
<div class="middle-col">
<lightning-input
class="inp middle-col"
type="file"
onchange={handleFileUpload}>
</lightning-input>
</div>
</template>
Below is the test class I have tried:
import { createElement } from 'lwc';
import customRecordProcess from 'c/customRecordProcess';
describe('c-customRecordProcess', () => {
afterEach(() => {
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
});
const fileName = 'Test';
const uploadedFileId = '001992929';
it('Should upload the file', () => {
const fileName = 'Test';
const element = createElement('c-customRecordProcess', {
is: customRecordProcess
});
it(this.uploadedFileId != null, () => {
assert.equal(this.uploadedFileId, '001992929');
});
});
Now when I run this, I am getting error as
> Pattern: - 0 matches npm ERR! code ELIFECYCLE npm ERR! errno 1 npm
> ERR! salesforce-app@1.0.0 test:unit: `sfdx-lwc-jest` npm ERR! Exit
> status 1 npm ERR! npm ERR! Failed at the salesforce-app@1.0.0
> test:unit script. npm ERR! This is probably not a problem with npm.
> There is likely additional logging output above.
Being new to JS testing, I am in process of troubleshooting what's wrong here. Can anyone please help me out on how to get this done?
npm run test:unit
to run test from VSCode Terminalnode_modules/.bin/lwc-jest
; presumably that sets up the required LWC environment.