Test negative scenario for readfile ,not working properlyHA

Viewed 18

Have a function that takes the file_path and file_name and then tries to read the file from the location the function looks as below

public processArtifact(artifact:Artifact): Promise<Artifact> {
        
        const file_path = path.resolve(artifact.getfile_path());
        let analytics_meta: any[] = [];
        let pipeline_meta: any[] = [];
        return new Promise(async(resolve,reject) => {
            fs.promises.readFile(file_path)
                .then(async function(data) {
         //logic to be added                    
                })
                .catch(function(error) {
                    LoggerWrapper.error(`Error while fetching ZIP of ${artifact.getname()}`, error)
                    throw error;
                });
        })

so was trying to write the unit test case where in I provided the wrong file path ,expecting the error to be thrown but that doesnt happen

unit test in jest is as follows

test('test loadasync method', async()=>{
   
    const mockGetRestClient = jest.fn();
   

    try{
      const response = await artifactService.processArtifact(wrongArtifact)
      const a = response
     
    }
    catch(e: any){
      const ea  = e ;
     }
  })
    

I get nothing in the catch block of unit test, please guide me as to how to write this properly new to jest

0 Answers
Related