Unit Tests for Redux Sagas and APIs

  1. Since Sagas are async in nature, we make the callback function inside the it function as async. By doing this we will be able use await to wait for our saga to get completed.
  2. Inside the callback function, we start by creating a fake store. Now a store gives us two methods: A getState function, which when called will return the store and a dispatch function which helps in triggering actions.
  3. Then we stub our ApiCallHelper.getDataFromAPI to return true. By doing this we are setting the value to be true, which is supposed to be returned from our API function, getDataFromAPI.
  1. It should call the API method.
  2. and then dispatch the desired action object.
  1. Success scenario, using MockAdapter return 200
  2. Failure scenario, using MockAdapter return !200

--

--

--

Been working on JS for the last few years. At present I’m a SSE at Intuit focusing predominantly on UI. www.linkedin.com/in/aniket-paul-0400279a

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Creating accordions with native HTML

How to disable Nextjs Telemetry data collected

Maximum AND value of a pair in an array

How to fix/update “Error: initial exceeded maximum budget.” in Angular

First attempts with TDD

Get Free Corn Price API in JSON

Scrift — Part 1: Getting Started

Should We Take The Redux Path?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aniket Paul

Aniket Paul

Been working on JS for the last few years. At present I’m a SSE at Intuit focusing predominantly on UI. www.linkedin.com/in/aniket-paul-0400279a

More from Medium

How Objects behave with Variables and Methods

Inversion of Control (IoC) in programming

Councilor Hamman answers Neo while laughing:  Of course. That’s it. You hit it. That’s control, isn’t it?

Design Patterns — 3

Quick Sort Algorithm