Mocking React Components and Functions using Jest for Beginners - React.js Testing Tutorial #5
Автор: Bruno Antunes
Загружено: 2021-08-09
Просмотров: 67124
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 Test...
----
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
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: