React Testing - To Mock or Not To Mock
Автор: Programming with Basar
Загружено: 2021-12-09
Просмотров: 220
Описание:
This is taken from my course, React with Test Driven Development at udemy. Here is the discount link https://bafoly.com/?course=tdd-react
When testing our components, some of our actions may trigger api requests to backend. But in test environment, we cannot rely on to a real http request going to backend. If we forget to start the backend, then the tests will fail here. But that does not mean we have problem with our application implementation. So to get consistent test results, instead of relying to an external service, like this backend for this case, we will mock the behavior. And we will use jest's mocking functionality to mock the axios.
But mocking couples our test with the implementation detail. Instead of axios, we can use fetch and we can achieve the same behavior, but our test would be failing when it is specifically mocking the axios package. Better approach for this case, is to use Mock Service Worker - MSW in our test environment. With this way, our tests won't need to know anything about the http client we are using.
Like, subscribe, comment any interaction with my channel, means a lot. Thanks
About me:
My name is Basar Buyukkahraman. I've courses for Spring Boot, React, Node.js, Web Components, Svelte and Vue in udemy.
Test Driven Web Development with Spring & React - https://www.udemy.com/course/test-dri...
Test Driven Development with Node.js - https://www.udemy.com/course/test-dri...
Git - Step by Step Guide - https://www.udemy.com/course/git-step...
Fundamentals of Web Components - https://www.udemy.com/course/fundamen...
Svelte with Test Driven Development - https://www.udemy.com/course/svelte-w...
Vue with Test Driven Development - https://www.udemy.com/course/vue-with...
React with Test Driven Development - https://www.udemy.com/course/react-wi...
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: