Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
Jest test case is failing in nestjs

I have below method in nestjs in service class.

async findOne(id: string): Promise<Certificate> {
    const result = await this.certificateRepository.findOne({ id });
    if (!result) {
        throw new NotFoundException(`Certificate with ID does not exist`);
    }
    return result;
}

I have writtern below test case for the same.

it('should find one certificate', async () => {
        const id = '1';
        const certificate = await service.findOne(id);
        expect(repository.findOne).toHaveBeenCalledTimes(1);
        expect(repository.findOne).toHaveBeenCalledWith(id);
        expect(certificate).toBeInstanceOf(Certificate);
    });

I am getting below error on the same.

I am not sure why it is returning object instead of value. if I cant modify the method can I modify this test case to retunr object?

WHat changes I should do in my testcase?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Update the assertion to be the following:

expect(repository.findOne).toHaveBeenCalledWith({ id: "1" });

This will match what how the code uses id to call certificateRepository.findOne.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!