Skip to content
Permalink
Browse files

Add HMR test for createOffline API

Also makes the implementations more consistent.
  • Loading branch information...
wacii authored and sorodrigo committed Feb 15, 2018
1 parent 84e7bc5 commit 9dc4f5a5a42730a79b0b5fec1dd4378da4171e62
Showing with 18 additions and 7 deletions.
  1. +15 −0 src/__tests__/index.js
  2. +3 −7 src/index.js
@@ -50,6 +50,21 @@ test("supports HMR by overriding `replaceReducer()`", () => {
expect(store.getState()).toHaveProperty("offline");
});

test("createOffline() supports HMR", () => {
const { middleware, enhanceReducer, enhanceStore } =
createOffline(defaultConfig);
const reducer = enhanceReducer(defaultReducer);
const store = createStore(reducer, compose(
applyMiddleware(middleware),
enhanceStore
));
store.replaceReducer(combineReducers({
data: defaultReducer
}));
store.dispatch({ type: "SOME_ACTION" });
expect(store.getState()).toHaveProperty("offline");
});

// see https://github.com/redux-offline/redux-offline/issues/4
test("restores offline outbox when rehydrates", done => {
const actions = [{
@@ -47,20 +47,16 @@ export const offline = (userConfig: $Shape<Config> = {}) => (
: offlineMiddleware;

// create store
const initialStore = offlineEnhancer(createStore)(
const store = offlineEnhancer(createStore)(
offlineReducer,
preloadedState,
enhancer
);

const baseReplaceReducer = initialStore.replaceReducer.bind(initialStore);
const replaceReducer = function replaceReducer(nextReducer) {
const baseReplaceReducer = store.replaceReducer.bind(store);
store.replaceReducer = function replaceReducer(nextReducer) {
return baseReplaceReducer(enhanceReducer(nextReducer, config));
};
const store = {
...initialStore,
replaceReducer
};

// launch store persistor
if (config.persist) {

0 comments on commit 9dc4f5a

Please sign in to comment.
You can’t perform that action at this time.