Mock Axios with Jest in Typescript and React (in 2 minutes)

preview_player
Показать описание
Mock Axios with Jest, Typescript and React, in just 2 minutes.

First, I'll show you how to mock Axios with Jest in any Typescript function, which could be Node, React or Angular.

Then, I'll show you how to mock an async component in React with React Testing Library and Jest.

I'll show you how you can use Jest's built-in mocking features to mock Axios in Javascript or Typescript, using either Node or React.

The Github repo for this video:

Timecodes:

00:00 - Intro
00:20 - Unit test an Axios function in Typescript
00:41 - Why should we mock functions?
01:02 - Create the Axios Unit Test
01:58 - Unit Test React Async Components with React Testing Library

#axios #unittesting #react #typescript #jest
Рекомендации по теме
Комментарии
Автор

This is great, keep it up :). Just a suggestion to use absolute paths everywhere in the project, it's more error prone to mock and maintain relative paths

hussaina.
Автор

my scenario - I did not export any get functions in my code so in that case how will I test.? please help!

purushothamguda