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

Publicado el: 09 agosto 2021
en el canal de: 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


En esta página del sitio puede ver el video en línea Mocking React Components and Functions using Jest for Beginners - React.js Testing Tutorial #5 de Duración hora minuto segunda en buena calidad , que subió el usuario Bruno Antunes 09 agosto 2021, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 57,189 veces y le gustó 779 a los espectadores. Disfruta viendo!