Тёмный

How To Test React Query Components 

Maksim Ivanov
Подписаться 29 тыс.
Просмотров 25 тыс.
50% 1

📘New Course: Build full-stack React Typescript applications tsreact.maksim...
In this video we will write tests for a component that uses ReactQuery to fetch and update data. Let me know in the comments if you want to see how to test our custom hooks.
Code: github.com/sat...
🐦 Twitter: / ivanov_dev
I write about React and TypeScript there
Code: github.com/sat...
Discord: / discord
Mailing List: mailchi.mp/819...

Опубликовано:

 

4 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 40   
@realyozza
@realyozza 3 года назад
Thanks for sharing Maksim!
@sangminna2308
@sangminna2308 Год назад
This is one of the greatest testing video, it's really helpful, thank you so much!
@aleks6331
@aleks6331 3 года назад
Great content Maksim! Could you please update repo with created test files?
@gavinlindridge
@gavinlindridge 3 года назад
Agreed, It would be really cool if you could please push your test changes if you still have them?
@GaryMenzel
@GaryMenzel 3 года назад
I think it would be great to see how to test the hooks themselves. I am already doing hook abstractions to allow for mocking tests, so it would be good to be able to test those independently.
@yafiecake
@yafiecake 2 года назад
true. have u done it Gary? I want to learn how.
@SuperFerrox
@SuperFerrox 3 года назад
Great video very interesting, greetings from Salta, Argentina.
@georgekalogeropoulos1813
@georgekalogeropoulos1813 3 года назад
Why are you checking if Book form got the default values?Isn't it better to just search for the elements that should appear,more like an integration test?
@CTBell-uy7ri
@CTBell-uy7ri 2 года назад
Helped a lot, thank you
@matsomo
@matsomo Год назад
excellent tutorial
@juliusngwu
@juliusngwu 3 года назад
Thank you for the video
@viksitagarwal1923
@viksitagarwal1923 3 года назад
Great Video, please also show how to test the hooks
@Marcoserod
@Marcoserod 2 года назад
Really helpful video! Do you know if there is a way to test with which parameters a query has been refetched ?
@intekhabalam3833
@intekhabalam3833 2 года назад
it was nice tutorial thanks for this, but "how can we mock the useMutation using TypeScript"
@claudioseccia9380
@claudioseccia9380 3 года назад
thanks!!! super cool content!
@satansdeer1
@satansdeer1 3 года назад
Thank you ☺️
@valerymbele4451
@valerymbele4451 3 года назад
Yes please, test the custom hooks
@kurans2000
@kurans2000 2 года назад
I have hook which uploads file, it has a lot of logic within hook itself, would be great if we could see example how to test hook which is using useMutation inside
@dorin6880
@dorin6880 Год назад
Thanks. Great explanation.
@viniciusataidedealbuquerqu2837
@viniciusataidedealbuquerqu2837 2 года назад
great video! what shortcut did you use to run the only available test?
@tsooooooo
@tsooooooo 2 года назад
Nice vid but with this approach it seems like the system under test is quite small. You're just testing rendering logic, not exercising the hooks. I'd rather mock the api layer and test the hooks in isolation. Then refactor the presentation components so they just take results of hooks and can be tested without mocks. Also, the expect toHaveBeenCalledWith is testing the implementation (enzyme style), not the behaviour, making it harder to maintain if you want to refactor internals - react testing library is intended to be analogous to a real user clicking around etc (at component level - not full e2e).
@satansdeer1
@satansdeer1 2 года назад
Fantastic comment, I’d love to discuss react testing approaches with you. Would you mind jumping on a stream someday?
@tsooooooo
@tsooooooo 2 года назад
@@satansdeer1 hah, I'm a grumpy old man, probably not palatable to your audience. Happy to discuss offline though
@chetan9533
@chetan9533 Год назад
@@tsooooooo wouldn't testing hooks also be similar to testing implementation/enzyme style?
@chetan9533
@chetan9533 Год назад
I wish react was a bit more opinionated, there's too much freedom. I have understood the basic arrange -> act -> assert philosophy but having hard time trying to figure how to test react components 😅
@codingSoothram
@codingSoothram 3 года назад
@testing-library/react-hooks package will help to test hooks functionalities. const { result, waitForNextUpdate } = renderHook(() => useCustomHooks()); act(() => { result.current[0]('123'); }); await waitForNextUpdate(); expect(result.current[1].isSuccess).toBe(true);
@rppd2907
@rppd2907 2 года назад
I am using a custom hook calling an API i am following all the steps , exact code and i am getting : The module factory of `jest.mock()` is not allowed to reference any out-of-scope variables. Invalid variable access: jest. Tried the doMock still not working. Please help me . Would be much appreciated i am stuck 1 week on this... :(
@tomaszstanisz1786
@tomaszstanisz1786 Год назад
I have an issue now, then trying to wrap useQuery hook with `useCustomHook` then I have info error from React that i cannot use hooks not in React Component (capital first letter component) and i'm forced to wrap useQuert and useMutate with RaectComponent 🙄 Is it from new @tanstack react query v4 or am i doing domething wront? ?
@viksitagarwal6228
@viksitagarwal6228 3 года назад
Can you please also share the test code - *.spec.jsx files, along with setupTests.js files with the test code you have written in the video.
@VYuhim
@VYuhim 3 года назад
А что тестируют эти тесты, кроме того, что реакт отрендерил jsx ?)
@ArgishtyStepanyan
@ArgishtyStepanyan 3 года назад
cannot find the tests in the repo, can you please push the code to the repo?
@sebap_xc
@sebap_xc 3 года назад
hey, thanks for the great vid. how do you set up vscode to see the live testing icons in your file?
@apawar3099
@apawar3099 2 года назад
He added Jest extension on vscode
@jorgearaya3154
@jorgearaya3154 3 года назад
Thanks Thanks Thanks Thaaaaaaaaaaaaaaaaaaaaaaaaanks!!!!!!!!!! :D
@satansdeer1
@satansdeer1 3 года назад
You are welcoooooooooooooooooome
@AsifSaho-zz8cz
@AsifSaho-zz8cz Год назад
can you cast another for react router v6?
@claystation6360
@claystation6360 2 года назад
Hey @Maksim I'm curious if you'd recommend utilizing react query for an enterprise geospatial react-map-gl application in 2022?
@ОлегБаранчиков-ф5у
Че по тайпскрипту?
Далее
БАГ ЕЩЕ РАБОТАЕТ?
00:26
Просмотров 236 тыс.
skibidi toilet multiverse 042 Trailer
01:57
Просмотров 1,9 млн
У КОТЕНКА ПРОБЛЕМА?#cat
00:18
Просмотров 1 млн
React Query tips from the maintainer @tkDodo
16:19
Просмотров 24 тыс.
Introduction to Test Driven Development with React
20:38
Тестирование React приложения
1:03:02