Mock vs Spy in Testing with Jest: Which is Better?

  Рет қаралды 8,028

Dev tips by MoHo

Dev tips by MoHo

Күн бұрын

In this video, we explore the differences between mocks and spies in testing with Jest. We'll dive into the benefits and drawbacks of each approach, and help you determine which one is best for your specific use case. Whether you're a seasoned developer or just starting out with Jest testing, this video is a must-watch. Join us as we explore the world of Jest testing and help you become a better developer.
Link to the Code example: github.com/mohokh67/jest-mock...
Jest Mock: jestjs.io/docs/mock-functions
Jest Spy: jestjs.io/docs/jest-object#je...
Chapters:
0:00 - intro
2:58 - Write tests
5:30 - Write mocks in jest
11:27 - Write spy in jest
20:58 Mock and Spy comparison

Пікірлер: 18
@Romul3003
@Romul3003 11 ай бұрын
Great tutorial, terrible editor fonts, my eyes are bleeding
@scally9341
@scally9341 9 ай бұрын
^
@dev.channel
@dev.channel 7 ай бұрын
Thanks for the feedback. I will not use this font in future videos
@edwarddemesaify
@edwarddemesaify Жыл бұрын
Excellent tutorial... Thank you!
@sandyrubybassi3462
@sandyrubybassi3462 2 ай бұрын
Best explanation i’ve come across 👌🏼
@BarakAlmog
@BarakAlmog 3 ай бұрын
Appreciate your effort so much! Thanks. I agree the font is a bit of a challenge,... still like it tho :) Thanks again!
@Maverick2k
@Maverick2k 4 ай бұрын
Just wanted to give kudos for your videos. I'm a senior dev, finally dabbling in proper testing and I found this video really easy to understand. I was wondering though, what which point is it better to spy vs mock?
@RRCaddick
@RRCaddick Ай бұрын
This is awesome! Was pulling my hair out yesterday dealing with jests mock hoisting and trying to change mock resolved for only a specific test, and I'm sure this will help. Why would we favour one over the other?
@Mr_MicDaniel
@Mr_MicDaniel 2 күн бұрын
I really enjoyed the tutorial it was superb Can you do this for Vitest and Prisma ORM. Thank I will really appreciate it
@malgorzatastefanowicz4077
@malgorzatastefanowicz4077 8 ай бұрын
cant watch it because of the font :/
@dev.channel
@dev.channel 7 ай бұрын
Sorry for that. I will not use that font in future videos
@aryakhaleqi1600
@aryakhaleqi1600 Жыл бұрын
Graet
@sueluceromartinezherrera1825
@sueluceromartinezherrera1825 11 ай бұрын
thanks! it was pretty clear, I just have a question, in this case the user file export the functions and you can import easily, but what happen if in my file The functions is not exported ? how can I access to that fuction in my test, hope I could be clear, greeting from mexico.
@dev.channel
@dev.channel 8 ай бұрын
If it’s not exported then it can’t be imported and not tested either
@justinmiller3349
@justinmiller3349 7 күн бұрын
@@dev.channel To be more precise, "private" or "internal" functions are not tested *directly* but as a developer you want to be aware of this and you can design your tests to ensure all of your internal logic is behaving as intended indirectly by ensuring that the imported function returns what is expected given several different inputs that the internal logic deals with. Using the --coverage flag with Jest can help uncover untested internal code.
@iJuce
@iJuce 8 ай бұрын
Why would you upload a video with that font 🤦🏽‍♂️ it’s so unreadable
@dev.channel
@dev.channel 7 ай бұрын
Thanks for the feedback. I will remember to not use that :)
@josuetavares49
@josuetavares49 Ай бұрын
with this font it is difficult to read
Patch any node package Like a Pro: Using PNPM, Yarn, and NPM
12:06
Dev tips by MoHo
Рет қаралды 2 М.
Unit Tests and Test Doubles like Mocks, Stubs & Fakes
17:32
Cognitive Programmer
Рет қаралды 129 М.
Do you have a friend like this? 🤣#shorts
00:12
dednahype
Рет қаралды 11 МЛН
ПЕЙ МОЛОКО КАК ФОКУСНИК
00:37
Masomka
Рет қаралды 9 МЛН
Тяжелые будни жены
00:46
К-Media
Рет қаралды 3,1 МЛН
Mocking Asynchronous Functions with Jest
21:50
Swashbuckling with Code
Рет қаралды 65 М.
Professional Python Testing with Mocks
21:19
NeuralNine
Рет қаралды 37 М.
#LETSMEETUP - JavaScript testing: Jest mocks
11:50
Codete
Рет қаралды 39 М.
React Testing Tutorial (Jest + React Testing Library)
22:16
Kris Foster
Рет қаралды 235 М.
Angular Testing in 2023: Past, Present, and Future
26:21
Rainer Hahnekamp
Рет қаралды 10 М.
Mocking Axios in Jest + Testing Async Functions
17:43
Leigh Halliday
Рет қаралды 82 М.
This is the Only Right Way to Write React clean-code - SOLID
18:23
Mocking a Database in Node with Jest
13:29
Sam Meech-Ward
Рет қаралды 62 М.
Introduction To Testing In JavaScript With Jest
13:57
Web Dev Simplified
Рет қаралды 484 М.
Introducing GPT-4o
26:13
OpenAI
Рет қаралды 4,2 МЛН
Пленка или защитное стекло: что лучше?
0:52
Слава 100пудово!
Рет қаралды 2 МЛН
Приехала Большая Коробка от Anker! А Внутри...
20:09
РасПаковка ДваПаковка
Рет қаралды 71 М.
Я Создал Новый Айфон!
0:59
FLV
Рет қаралды 3,6 МЛН