Helping a subscriber learn Jest and mocking a bit

preview_player
Показать описание
------------

Рекомендации по теме
Комментарии
Автор

Great video. I actually ran into the same problem yesterday.
You can solve the mocked prisma type issue by importing the real prisma object and then only mocking the specific function (for example: import prisma from ‘./client’; prisma.like.create = jest.fn().mockResolvedValue({})), or you could force the type of your mocked prisma adding ‘as PrismaClient’ (for example: const prismaMock = {like: {create: jest.fn() }} as PrismaClient )
Both approaches will make the TS compiler happy.
I do prefer the first approach tho, because it is ok if your test has a dependency if the original class has that dependency as well. I know you are injecting the prisma client dependency, but in order to be truly decoupled, that argument should be typed as an abstract class or interface that implements what you need as a prisma adapter. In that case, the test should definitely not depend on the prisma client but on mocked instance of that interface/abstact class
Thanks for the video!

carlo.casorzo
Автор

I really like your channel, just that it's mostly front-end focused, would love to see some Node stuff

NathanielBabalola
Автор

Pls make a video on calculating hosting cost of a webapp.

MudassirKhan-sxjy
Автор

sir how to connect with you. i want to resolve an issue im having with a website

rahul-ticm
Автор

What you did is not unit test.. that's integration test. And tests should be api agnostic (changing connection, db, db driver and so on) this one isn't.

RaZziaN