How to mock an npm package with Vitest/Jest

preview_player
Показать описание
Mocking an npm package / module in Vitest can be a tricky thing. The mock function works in such a way that it can easily confuse you and get you stuck, especially when you want part of your test cases to use the mocked version of it, but the other part the original. In this video I'll show you how you can achieve that.

--

--

Chapters:
00:00 - Intro
00:39 - The problem
01:20 - The reason
01:53 - What you think might be the solution
03:11 - Solution #1
04:07 - Solution #2
09:21 - Recap
Рекомендации по теме
Комментарии
Автор

Hope you like this video! I got confused when I tried mocking the nanoid package the first time, so I thought I'd record this so you don't have to spend time figuring it out. Make sure to watch until the end because there are two solutions, not just one (like I mention in the video 😂). Thanks for watching! Don't forget to like and sub if you like content like this 🙏

nikolovlazar
Автор

I appreciate this helpful video but one thing to point out, I hate tutorials that doesn't include a warning for the side effects of what they are teaching in a crash course and most of them when the video got many views, they won't even correct it or change the content. Just like in this video at solution #1, but it's also great that it is corrected in solution #2. Kudos!

dev-vffm
Автор

Letss goo, mocking data from queries is the same trouble. Been dealing with jest from the beninging and im only in this field for a year now. Testing is rly important where hundreds of players play on the same field. With tests we controll the behavior and its a legit thing. Happy hacking and salute from Macedonia

itachi
Автор

Bro, how come I just discovered your channel

Your setup is leet. I use neovim tmux, only backend tho with typescript and sometime Golang

Is that keyboard a voyager ? Are you still using qwerty for the vim keybind or using another layout ?

Keep it up bro, your videos are pur gold

SayfSentinel
Автор

Hi Lazar, I have been watching your live on Clean Architecture and i loved it.

can you create a long video building enterprise level application from scratch?

a humble request from a subscriber😊

mhdyousuf
Автор

Please can you make a vitest and react testing library masterclass for Next.js, Iam struggling

AHMEDYASSER-upyx