Mocking Asynchronous Functions with Jest

preview_player
Показать описание
Mocking is a fundamental skill in testing. It allows you to avoid testing parts of your code that are outside your control, or to get reliable return values from said code.

00:00 - What we'll cover
01:00 - Reviewing the project setup
03:02 - Creating the test
06:24 - Adding async await to pass test
07:17 - Why mock an api request for unit tests
08:32 - Adding jest mock for axios
14:06 - Check if mock function has been called
15:31 - Shorthand for mocking resolved promise value
16:23 - Gotcha for mock state, and how to clear it each test
18:24 - Alternate way of mocking within a test file
20:50 - Wrap-up

Repository for code example:

Blog Post:

Swapi Dev:

Follow Jimmy Cleveland's doings:

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

This is by far the best video I've found explaining mocking Jest

sharonfitzpatrick
Автор

I will personally hunt down anyone who downvotes this tutorial. Outstanding presentation.

jimmymac
Автор

God Bless you or whatever. I lost a whole day trying to figure out how to call my test async. So true how "it might not be so obvious to some" Thank You!

tachylamurray
Автор

I prefer blogs over videos, thankyou for making one and very understandable.

ShubhamKumar-mkzb
Автор

This is the best video about mocking I have encountered, it really made me understand how it works. Big thanks to you sir!

mateuszszaowicz
Автор

Thank you for taking us into traps and teaching us how to escape/fix them.
Short, precise, and easy to understand, also with sections that you can jump around and quickly learn what you need. 👍 Amazing.

imekachi
Автор

Thank you so much, Jimmy! You're slowly demystifying testing JS code with Jest for me!

viridianite
Автор

Thank you so much! This is really useful to understand how mocking works under the hood, helps you thinking of what's going on to figure out issues with testing. Helped me a lot.

LeoMuzi
Автор

Great video...thanks for explaining jest mocks.

SwOOp_de
Автор

We have struggled with axios mocking on a complex React/Typescript project having only recently up-skilled. Best explainer!

petergoodey
Автор

This was the most useful video I ever watched about mocking functions using Jest. You've made it pretty simple to understand the concept. Nice job Jimmy!

jonathanlinat
Автор

this video is short and easy to understand, please make more videos for unit testing, it is helpful for a beginner like me. Thanks!

giachan
Автор

one of the simplest and well-explained clean video of jest mocking so far! thanks!

arfasaif
Автор

Needs to be more stuff of this quality on the net. Most explanations are too simplistic and are aimed at people with no experience.

Alan.livingston
Автор

Wow I was really struggling with this but got it to work thanks to your videos. Thank you js Jesus

gordemn
Автор

The way you teach is fantastic! And yes, this is the best video on the topic.👏👏 Thank you so much

vikramin
Автор

Thanks for this content. (from India
)

JoseciusDev
Автор

Thank you! This was so useful to me. Gonna be watching some more of your Jest videos now. :)

aglowkeys
Автор

An excellent resource in my current journey in Unit testing

CristianAndresNietoGarcia
Автор

Thank you. You earned a subscriber at "Sanity check" . Awesome bro.

emmanuelsackey