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) {
            this.customFileIds.push({Id: result, Title: file.name});
            if (this.fileName === null) { 
                this.fileName = file.name;
                this.customFileId = result;
            let file = event.target.files[0];
            let reader = new customReader();

Below is my HTML Code:

        <div class="slds-grid">
            <lightning-formatted-text class="left-col" value=""></lightning-formatted-text>
            <div class="middle-col">
                    class="inp middle-col" 


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) {
 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?

  • 1
    What have you tried? Where are you stuck? Could you edit your post to include your attempts at a test class and a specific challenge you're working on?
    – David Reed
    Dec 7, 2020 at 4:57
  • @DavidReed, I have updated my question. Please suggest
    – SFDCUser
    Dec 7, 2020 at 5:05
  • Add how you are running the test. Personally, most of the time I run tests from VSCode. Also start with a test that does nothing to separate problems in running the test from problems in the content of the test.
    – Keith C
    Dec 7, 2020 at 11:31
  • @KeithC I'm running the test from VSCode. I'm using npm run test:unit to run test from VSCode Terminal
    – SFDCUser
    Dec 7, 2020 at 12:34
  • I usually use the "Run Test" link that is inserted into the test edit view or the green arrow in the top right. They run the node_modules/.bin/lwc-jest; presumably that sets up the required LWC environment.
    – Keith C
    Dec 7, 2020 at 12:54


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.