consolidation of various example repos/gists

This commit is contained in:
2021-07-15 11:36:18 +02:00
parent 58142d3157
commit 16953bd936
20 changed files with 978 additions and 1 deletions

View File

@@ -0,0 +1,66 @@
import { PENDING, FULFILLED, REJECTED } from "redux-promise-middleware";
export default function handleReduxPromiseMiddleware(
reducer,
actionType,
initialState,
statusKey,
meta = {}
) {
it(`should handle ${PENDING} (redux-promise-middleware)`, () => {
let taintedState = Object.assign({}, initialState);
taintedState[statusKey] = "TAINTED";
const pendingAction = {
type: `${actionType}_${PENDING}`,
payload: PENDING,
meta: meta,
};
expect(reducer(taintedState, pendingAction)[statusKey]).toEqual(PENDING);
});
it(`should handle ${REJECTED} (redux-promise-middleware)`, () => {
let taintedState = Object.assign({}, initialState);
taintedState[statusKey] = "TAINTED";
const rejectAction = {
type: `${actionType}_${REJECTED}`,
payload: REJECTED,
meta: meta,
};
expect(reducer(taintedState, rejectAction)[statusKey]).toEqual(REJECTED);
});
it(`should handle ${FULFILLED} (redux-promise-middleware)`, () => {
let taintedState = Object.assign({}, initialState);
taintedState[statusKey] = "TAINTED";
const fulfillAction = {
type: `${actionType}_${FULFILLED}`,
payload: FULFILLED,
meta: meta,
};
expect(reducer(taintedState, fulfillAction)[statusKey]).toEqual(FULFILLED);
});
}
/**
USAGE:
import {
handleReduxPromiseMiddleware
} from "redux-promise-middleware.spec.js";
handleReduxPromiseMiddleware(
reducer,
"ACTION_KEY",
initialState,
"status", {
data: {
access_token: "",
token_type: ""
}
}
);
**/