#LETSMEETUP

  Рет қаралды 40,230

Codete

Codete

Күн бұрын

#LETSMEETUP
💬 In this episode, a Senior Frontend Developer at Codete - Magda Kwiecień, will shed some light on using test mocks in one of the most popular JavaScript testing frameworks - Jest. From simple basics to a few lifehacks.
You can explore presented examples on Github:
github.com/kwieccia/jest-mock...
Chapters:
0:00 Intro
0:21 What is mock?
0:42 Why do we need mocks?
2:06 Use cases
2:38 jest.fn()
3:58 jest.spyOn()
5:47 jest.mock()
7:24 Global mocks
8:15 Different function mocks for each test case
9:08 Restore original function for a single test case
9:38 Deal with jest.mock() hoisting
Follow us 👉 / codete
Instagram 👉 / codete_career
Join us 👉 codete.com/career

Пікірлер: 58
@saltwaterkamp
@saltwaterkamp 4 ай бұрын
Absolute straight to the point of the Jest-Mocking API summary of what I need to know right now. Thanks!
@cachipum
@cachipum Жыл бұрын
Great explanation. This is definitely the best video about jest mocking I've found over youtube , thank you so much Magda!
@CodeteSoftware
@CodeteSoftware Жыл бұрын
Thank you! We will definitely pass on the kind words to Magda!
@EdytaKawala
@EdytaKawala 5 ай бұрын
I felt so overwhelmed - learnig testing and mocks right now. This video is godsent! Thank you
@magdakwiecien5530
@magdakwiecien5530 4 ай бұрын
Pozdrowienia z Lublina! Powodzenia w nauce ☺
@Serkan0kur
@Serkan0kur 2 жыл бұрын
Great job Magdalena, it is amazing to find everything I need about mocking in one video with examples.
@artavazdavagyan
@artavazdavagyan 2 жыл бұрын
Nice to hear from someone who has experience with testing. over 90% of the videos are usually from people that have just red the manual and have no practice
@jettlaggg
@jettlaggg Жыл бұрын
I've been reading articles and watching videos about jest mocks and no one explained it as clear and concise as this video. Thank you!
@CodeteSoftware
@CodeteSoftware Жыл бұрын
thank you!
@gmjitendra
@gmjitendra Жыл бұрын
Such a great job done by you Magdalena. You covered all which I was looking for since long. Thank you very much for explaining and sharing code repo.
@olayinkaola9857
@olayinkaola9857 2 жыл бұрын
This is such a packed video. THANK YOU! 1.Functions Mocking using jest.fn(). e.g. Testing a utility 2. Methods mocking using jest.spyOn(). e.g Testing a DataService. Here she tested the dependencies of the DataService. 3. You can mock entire modules using jest.mock(). Jest will automatically provide mock implementations for each methods of this module. You can also selectively override portions of the module by spreading jest.requireActual, and override your target method/function. TOP STUFF Use jest.mock to: 1. simulate JSON config. 2. External Node modules 3. Testing React Components with Enzyme/React Test Library Declare global mocks in your jest.config.js file by listing it under the setupFiles key. Use global mock files to mock GLOBAL STUFF(window object methods and browser APIs). Remember to always set your test environment in jest.config.js You can skip the clever parts for now. But internalise the solution to jest.mock() hoisting problem. The problem is making sure your values are available before use. USE jest.doMock(). They are not hoisted. USE the require statement to import your module. ** Memorize the USE CASES ** ** Watch the video with subtitle on [CC]. **
@magdakwiecien5530
@magdakwiecien5530 2 жыл бұрын
And thank YOU for providing the great summary! 😊
@muhammadporagsarkar7269
@muhammadporagsarkar7269 Жыл бұрын
Commenting after watching a lot of videos on this topic and by far this is the most indept yet super easy to understand tutorial... Would have given 100 thumbs up if I could...
@CodeteSoftware
@CodeteSoftware Жыл бұрын
@Liam.Stevens
@Liam.Stevens Жыл бұрын
Great video! Helped me a lot. Especially the differences between each of the functions
@vinr
@vinr 2 жыл бұрын
Super, it covered all the issues I had on jest mocking in 10 mins
@magdakwiecien5530
@magdakwiecien5530 2 жыл бұрын
Happy to hear that! 🙌
@oraclejetster9919
@oraclejetster9919 Жыл бұрын
Magda for president!
@perrosaurio725
@perrosaurio725 Жыл бұрын
Thanks, this made it a lot easier to understand.
@Alexis-ei9ct
@Alexis-ei9ct Жыл бұрын
Very clear and concise! Thank you for sharing it.
@user-tg5ry7yg1w
@user-tg5ry7yg1w Жыл бұрын
This is an excellent video
@wildcat718
@wildcat718 Жыл бұрын
thanks! this video answered my long lasting questions
@CodeteSoftware
@CodeteSoftware Жыл бұрын
We're delighted and encourage you to subscribe so you don't miss out on more valuable videos on our channel !
@agnieszkakrawczyk6107
@agnieszkakrawczyk6107 2 жыл бұрын
Very interesting content. Magdalena, good job!
@koderfpv1638
@koderfpv1638 2 жыл бұрын
Great vid! Thanks for table of content! IT will be easier to go back to some topics!
@stefc4663
@stefc4663 Жыл бұрын
A fantastic video. That last bit about jest.mock hoisting is soo good to know. Those gotchas can take a long time to troubleshoot.
@CodeteSoftware
@CodeteSoftware Жыл бұрын
Thank you, we really appreciate it!
@AGAGARCIA
@AGAGARCIA 2 жыл бұрын
Great Video, and Great explain. Good examples. Thanks.
@oneblackpanda
@oneblackpanda 9 ай бұрын
thank you very much...
@jorgesanguinetti1586
@jorgesanguinetti1586 Жыл бұрын
Great video. Is there a place where to find more examples? The official doc is a bit confusing.
@sprintwithcarlos
@sprintwithcarlos Жыл бұрын
This is a great instructional video, congrats
@CodeteSoftware
@CodeteSoftware Жыл бұрын
Thanks Carlos, we appreciate it!
@fredlove1402
@fredlove1402 11 ай бұрын
Thank you! Very helpful!
@CodeteSoftware
@CodeteSoftware 11 ай бұрын
Thanks!
@GeorgeBora
@GeorgeBora Жыл бұрын
A really good explanation, thank you.
@Couchwurst
@Couchwurst 2 жыл бұрын
Perfect! Thank you!! :D
@user-ci5hf5oe1f
@user-ci5hf5oe1f Жыл бұрын
super clear, thanks!
@jvinhit
@jvinhit Жыл бұрын
Great! Thank you for your sharing!
@haniamania5884
@haniamania5884 Жыл бұрын
Super merytorycznie i prezentacyjnie. Jak udalo Ci sie zrobic takie fajny zoomy bez zadnych drgan/ utraty jakosci? 🙂
@zapfska7390
@zapfska7390 Жыл бұрын
I stack overflowed for hours and she covers it all. just missed one thing about mocking modules using __esmodule: true
@nirash8018
@nirash8018 2 жыл бұрын
Thank you Skrillex
@kobas8361
@kobas8361 Жыл бұрын
Rewelacyjny materiał
@CodeteSoftware
@CodeteSoftware Жыл бұрын
Dzięki, zachęcamy do obejrzenia pozostałych filmów
@ProgrammingWithOsku
@ProgrammingWithOsku Жыл бұрын
very nice
@johnswanke6517
@johnswanke6517 Жыл бұрын
Wow
@eliasvasques80
@eliasvasques80 10 ай бұрын
A doubt: "spyOn" with "mockImplementation" really replace the implementation when my file function imports the "spyedOn" function. Or just the instance on the test that i may pass as a parameter?
@magdakwiecien5530
@magdakwiecien5530 10 ай бұрын
It will replace the real implementation - during the time of the test run. Even if this "spiedOn" function is used implicitly, deep inside a file/module/component. (For example, when you test a function from file X that imports a function from file Y that imports a file Z where the "spiedOn" function is declared, it will still be mocked/replaced).
@eliasvasques80
@eliasvasques80 10 ай бұрын
@@magdakwiecien5530 I really appreciate that you have responded me. Sorry my english isn't so good.
@hacking-multiboot904
@hacking-multiboot904 Жыл бұрын
exenté explicación
@adilsaeed31
@adilsaeed31 2 жыл бұрын
Great Video, I learned lots of new things from this video and you are so beautifull :)
@CodeteSoftware
@CodeteSoftware Жыл бұрын
Thank you! Stay with us!
@baboochiku
@baboochiku Жыл бұрын
Zuberrrrr
@korkut31
@korkut31 Жыл бұрын
all codes are wrong. wrong import. you can not resolve paths in JS with out extension. it it not TS.
@leojohn6702
@leojohn6702 5 ай бұрын
Me looking for jest tutorial: hey. wellcome to my advanced jest test. in this tutorial we will tests arrays of numbers. and sum of the elements a + 2 + {username: 'daniel'}; me looking for mooking a mongodb databaase: 😃😃😃😃 : ' yes. this is what I am looking for '
@CTBell-uy7ri
@CTBell-uy7ri 2 жыл бұрын
Yet another tutorial about mocking that doesn't show how to mock an actual npm package. I guess I'll have to keep looking.....
@magdakwiecien5530
@magdakwiecien5530 2 жыл бұрын
Hi, actually it's briefly mentioned at 7:08 - but yes, without detailed explanation, because I don't think there's something particularly complicated about mocking npm package compared to mocking your own, custom ES module. It's the same principle. Quick example, let's say that application uses "uuid" library somewhere: > import { v4 } from 'uuid'; The mock would look just like this: > jest.mock('uuid', () => ({ > v4: jest.fn(() => 'e4ca9391-470d-4d9b-b781-18436fe91c2c'), > }));
@up.to.mountains
@up.to.mountains Жыл бұрын
Акцент писец
@korkut31
@korkut31 Жыл бұрын
what kinda accent is that ? uuuu very disturbing. do u from polland ? Serbia ? uffff.
Mock vs Spy in Testing with Jest: Which is Better?
25:12
Dev tips by MoHo
Рет қаралды 9 М.
Как быстро замутить ЭлектроСамокат
00:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 13 МЛН
A pack of chips with a surprise 🤣😍❤️ #demariki
00:14
Demariki
Рет қаралды 31 МЛН
How to bring sweets anywhere 😋🍰🍫
00:32
TooTool
Рет қаралды 33 МЛН
JavaScript Testing - Mocking Async Code
18:05
Academind
Рет қаралды 144 М.
Professional Python Testing with Mocks
21:19
NeuralNine
Рет қаралды 41 М.
Jest Crash Course - Learn How to Test your JavaScript Application
1:06:53
Thoughts About Unit Testing | Prime Reacts
11:21
ThePrimeTime
Рет қаралды 206 М.
Next.js with React Testing Library, Jest, TypeScript
25:04
Dave Gray
Рет қаралды 52 М.
Mocking a Database in Node with Jest
13:29
Sam Meech-Ward
Рет қаралды 63 М.
Don't Mock 3rd Party Code
19:56
Continuous Delivery
Рет қаралды 38 М.
Mocking Axios in Jest + Testing Async Functions
17:43
Leigh Halliday
Рет қаралды 82 М.
Mocking Asynchronous Functions with Jest
21:50
Swashbuckling with Code
Рет қаралды 66 М.
Jest. Unit Тестирование в JavaScript
1:27:05
Владилен Минин
Рет қаралды 167 М.
AI от Apple - ОБЪЯСНЯЕМ
24:19
Droider
Рет қаралды 91 М.
i love you subscriber ♥️ #iphone #iphonefold #shortvideo
0:14
Si pamerR
Рет қаралды 2,7 МЛН
WWDC 2024 Recap: Is Apple Intelligence Legit?
18:23
Marques Brownlee
Рет қаралды 5 МЛН