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

998
Views
How can I mock Prisma client with es6 (Without typescript) in jest?

The Prisma Documentation has examples of mocking the client and doing unit testing using jest and typescript. Is there any way to mock the client in jest without using TypeScript?

I would be grateful if you can give a simple example.

Small Thing to add: I am using dependency injection in my project in all the functions that use the prisma.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

My solution for now: I am manually mocking the database object and passing it to the function that uses it: I am not sure how useful this but it helps avoid making calls to the real database.

const mocked_db = {
    user: {
        findFirst: jest.fn(() => Promise.resolve(
            {
                id: 2,
                first_name: "Basel",
                last_name: "Akasha"
            }
        ))
    }
}

it("It should work blah blah bla", async () => {
    let user_details= {
       id: 2,
       first_name: "Basel",
       last_name: "Akasha"
    }
    
    let signup = await getUser(
        mocked_db // takes thew DB object is a parameter (normally you would pass your Prisma client instance)
    )

    await expect(.... // whatever you'r expect is
})'
over 4 years ago · Santiago Trujillo 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!