vitest-mock-extended icon indicating copy to clipboard operation
vitest-mock-extended copied to clipboard

Mocking an async function call does not return mock value.

Open anhtuank7c opened this issue 1 year ago • 4 comments

  it('able to create user with prisma', async () => {
    const db: DeepMockProxy<PrismaClient> = mockDeep<PrismaClient>()
    // I do assign mock value for extension but it doesn't seem to return user
    db.user.create.calledWith({ data: user }).mockResolvedValue(user)
    const result = await db.user.create({ data: user })
    console.log('AAAA result', result ?? 'Nothing returned')
    expect(result).toBe(user)
  })

CleanShot 2024-02-03 at 10 54 01@2x

anhtuank7c avatar Feb 03 '24 03:02 anhtuank7c

Could you provide a minimal repo so I can check it out and debug?

eratio08 avatar Feb 04 '24 09:02 eratio08

Sorry I could not provide a minimal repo at this moment but the root issue happen with calledWith({ data: user }) Without trigger calledWith({ data: user }) the mock function work pretty well.

anhtuank7c avatar Feb 05 '24 08:02 anhtuank7c

For me to debug this a minimal repo would be very appreciated.

eratio08 avatar Mar 19 '24 06:03 eratio08

@eratio08 Sure, I will do it by this weekend. Thank you for notice

anhtuank7c avatar Mar 19 '24 15:03 anhtuank7c