HOW TO TEST JAVASCRIPT CODE USING JEST - TEST PURE FUNCTIONS | MOCK GLOBAL VARIABLES | TEST METHODS

HOW TO TEST JAVASCRIPT CODE USING JEST - TEST PURE FUNCTIONS | MOCK GLOBAL VARIABLES | TEST METHODS

Maksim Ivanov

4 года назад

3,524 Просмотров

📘New Course: Build full-stack React Typescript applications https://tsreact.maksimivanov.com/s/ytd

Here I show how to test your Javascript code. We will test pure functions (they are the easiest to test, because they don't have side effects). Then we test a function with side effects and we mock a global function using Jest. And finally we test an object method. We also talk about AAA (Arrange Act Assert) pattern here.

Code: https://github.com/satansdeer/test-example
DIscord Server: https://discord.gg/KPh8Vvb
Free React Testing Checklist: http://eepurl.com/c_8tzP

#testing #javascript #jest #satansdeer

Тэги:

#testing #javascript #javascript_testing #javascript_testing_for_beginners #javascript_unit_testing_for_beginners #jest_tutorial_for_beginners #jest_for_beginners #programming #satansdeer
Ссылки и html тэги не поддерживаются


Комментарии:

@no4e
@no4e - 14.06.2021 11:44

Как сделать ES6--модули доступными в Jest? У меня Jest ругается, но не пойму на что. Вроде бы версия норы позволяет использовать ES6-модули и в package.json установил нужный "type", но всё равно нет. Что делать ума не приложу. :(

Ответить
@jayzhao3123
@jayzhao3123 - 19.04.2021 07:12

can you please epxlain why alert is considered a side effect ? can you please provide more about what is an impure function ? Also for testing impure functions, we always need to mock by using spy correct?

Ответить
@codingexpedition4625
@codingexpedition4625 - 28.10.2020 14:14

Which extension would you use in vscode to run jest tests?

Ответить
@dumitrustratulat4257
@dumitrustratulat4257 - 08.07.2020 11:18

salut,cum faci testing la indexedDB?

Ответить
@TheRAWLEX
@TheRAWLEX - 06.06.2020 11:32

Качество бы повыше, а то только 360 было(

Ответить