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

Pubblicato il: 09 agosto 2021
sul canale di: Bruno Antunes
57,189
779

In this tutorial we are going to learn how to mock components and functions using the built-in features in jest.

We will use jest.mock, jest.spyOn, jest.fn(), _mocks_ folder and others.

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.

----
GitHub repository: https://github.com/bmvantunes/youtube...
----
All the videos in this series (React.js Testing Tutorial):    • React.js Unit Testing and Integration...  
----
Join the channel to support my content:
   / @brunoantunespt  
-----
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:
Twitter:   / bmvantunes  
Dev.to: https://dev.to/bmvantunes
Website: https://brunoantunes.net
GitHub: https://github.com/bmvantunes
LinkedIn:   / bmvantunes  

#jest #ReactTestingLibrary #react


In questa pagina del sito puoi guardare il video online Mocking React Components and Functions using Jest for Beginners - React.js Testing Tutorial #5 della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Bruno Antunes 09 agosto 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 57,189 volte e gli è piaciuto 779 spettatori. Buona visione!