Skip to content

Instantly share code, notes, and snippets.

View Gbaja's full-sized avatar

Fatimat Gbajabiamila Gbaja

View GitHub Profile
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.
@Gbaja
Gbaja / logout.test.js
Last active August 10, 2018 16:24
Code snippet for testing logout-test.js as needed in my Introduction to testing your redux blog code
import { mockStore, mockAxios } from "../test-support";
//importing our helper variables previously defined in setup stage.
describe("Logout action", () => {
it("Returns the correct action to log out a user", () => {
const mockLogout = () => mockAxios.onGet("/api/logout").reply(200);
//I am creating a mock log out function using the mockAxios variable which by default has access to methods built in to the module.
//I am using the onGet method to call our api. Notice how the string I pass in, is the same as the string I pass in to my axios.get method in my real logout function. It is important that it is the same.
//The reply method is checking to make sure my request is going through hence why I am passing in the status code 200.
import deepFreeze from "deep-freeze";
//importing deep-freeze, an npm module which helps to make sure I am not mutating state as that is the rule for a reducer
describe("Alert reducer", () => {
it("Adds an error", () => {
const initialState = {
type:"",
message:""
};
@Gbaja
Gbaja / airtable-sample-blog.js
Last active June 5, 2021 05:48
Example of how to retrieve and delete using the airtable api
// The information of the person you want to add
// Please note that they key has to match the wait the field is defined in your spreadsheet.
// The person table is linked to the Countries table. A person can have more than one country so you pass an array of all the countries Ids that the user belongs to.
const newPersonInfo = {
"First name": "Fatimat",
"Last Name": "Badmus",
Countries: ["recWWTmP55RDo2Abu"]
};
const createRecord = () =>