Mocking React Components and Functions using Jest for Beginners - React.js Testing Tutorial #5

preview_player
Показать описание
In this tutorial we are going to learn how to mock components and functions using the built-in features in jest.

Manual mocks are used to stub out functionality with mock data. For example, instead of accessing a remote resource like a website or a database, you might want to create a manual mock that allows you to use fake data. This ensures your tests will be fast and not flaky.

Mock functions allow you to test the links between code by erasing the actual implementation of a function, capturing calls to the function (and the parameters passed in those calls), capturing instances of constructor functions when instantiated with new, and allowing test-time configuration of return values.

There are two ways to mock functions: Either by creating a mock function to use in test code, or writing a manual mock to override a module dependency.

----
----
----
Join the channel to support my content:
-----
Timeline:
00:00 Intro
00:18 Example 1
06:55 Example 2a: Button
09:40 Example 2b: Data Grid
17:00 Example 3
19:50 Example 4
22:06 Example 5: Avoid mocking everywhere the same component
25:50 Outro
----

Follow me on:

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

Hi Brune, Really find this tutorials on testing helpful especially for a beginner into testing like me. Could you recommend another means of mocking react components as mocked - ts-jest/utils has been deprecated?😁

aolausoro
Автор

Thank the lord for this guy 👏I'm a junior dev' and I started working for a big company three months ago. I had no experience of testing and it has severely affected my performance in this role, I wish I had have seen this video two months ago but it's still useful for me. Lots of other jest videos out there are good, but pretty basic, this one is up to date and exactly how my company mocks so cheers Bruno.

P.s. I know it sounds like I'm this dude's friend giving him a nice review, but I don't care this video is deffo worth it for anyone who doesn't have a goosy about testing like myself a short while ago.

dannyroberts
Автор

This is the best testing video I've ever seen!

algodork
Автор

Hi Bruno, there are lots of testing tutorials on youtube but your tutorials are one of the best. Thank you for your great explanations. You took a break from youtube videos, I think you should continue. We're waiting for your new videos.

mithderlersam
Автор

This is by far the best tutorial on mock/spy that i have found. Thanks

qram
Автор

Finally, I've understood what spying and mocking is! Thanks!!!!

lucadifazio
Автор

El mejor tutorial de pruebas que he visto en la red. Te agradezco muchísimo Bruno!!

moibe
Автор

You gave my motivation back brother... Thank you so much :) So happy that i found your channel :)

PraveenKumar-ftkr
Автор

Amazing tutorial, better than the jest documentation itself, mocks are so powerful!

hillelgarcia
Автор

Super professional tutorial I've seen so far. Really many practical tricks explained here which our team spent years to figured out with Jest.
Still looking for a trick to save memory when jest is running.

GfastGao
Автор

Thank you Bruno for this wonderful series! 🤓👍👍👍

makstarr
Автор

This is an amazing series on test.
Simply wonderfull

vittoriomorellini
Автор

Oh my gosh, I spent all day yesterday looking at articles on how to do this and got nowhere. 6 minutes into your video and I have a passing test! Thanks!

paulpardee
Автор

Liking this before watching. Been a while since I have found one of your videos.

AnzarDtafukt
Автор

What a great video. Thanks for putting this together. Nice and clear

mrjebbar
Автор

Really helpful as always Bruno. Thank you !

sashaikevich
Автор

Excellent explanation, you gained another subscriber, congratulations!

gabrielfrancelino
Автор

Love your presentation man. awesome !!!

rezaverse
Автор

Very helpful, esp the last trick. Thank you.

GG-uzus
Автор

Thanks Bruno, it's hard to find jest with typescript out there

but I don't understand why without @jest/globals, your test files already has jest object typed it seems, how did you do the setup?

chapman