Created
August 10, 2018 16:08
-
-
Save Gbaja/e17f4093d28a9c324f0e2092b8314d5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import thunk from "redux-thunk"; | |
// redux-thunk middleware is what I use in development stage to handle my asynchronous actions. | |
import configureStore from "redux-mock-store"; | |
// redux-mock-store is a mock(fake copy) store for testing Redux async action creators and middleware. | |
//The mock store will create an array of dispatched actions which serve as an action log for tests. | |
import axios from "axios"; | |
//axios is a promised based module for creating HTTP requests I am using. | |
import MockAdapter from "axios-mock-adapter"; | |
//axios-mock-adapter is a module for creating a mock HTTP request | |
const middlewares = [thunk]; | |
//The middlewares variable is an array of all the redux middlewares used in development stage, in my case I am only using thunk thus why it is the only one listed. | |
const mockStore = configureStore(middlewares); | |
//The variable mockStore creates a fake store for testing purposes, basically doing the same thing as when you call the createStore() method in redux. | |
const mockAxios = new MockAdapter(axios); | |
//sets the mock adapter to the axios instance. | |
export { mockStore, mockAxios }; | |
// I am exporting both variables so I can use it when testing my action creator. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment