Socket
Socket
Sign inDemoInstall

redux-simple-router

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-simple-router - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

.eslintrc

7

CHANGELOG.md
## HEAD
* Update to the new history API (#89)
## [1.0.0](https://github.com/jlongster/redux-simple-router/compare/1.0.0...1.0.1)
* Solve problem with `basename` causing infinite redirects (#103)
* Switched to ES6 imports/exports internally, but should not affect outside users
## [1.0.0](https://github.com/jlongster/redux-simple-router/compare/0.0.10...1.0.0)

@@ -13,3 +16,3 @@ > 2015-12-09

* The `updatePath` action creator has been removed in favor of `pushPath` and `replacePath`. Use `pushpath` to get the same behavior as before. (#38)
* The `updatePath` action creator has been removed in favor of `pushPath` and `replacePath`. Use `pushPath` to get the same behavior as before. (#38)
* We have added support for routing state (#38)

@@ -16,0 +19,0 @@ * Our actions are now [FSA compliant](https://github.com/acdlite/flux-standard-action). This means if you are listening for the `UPDATE_PATH` action in a reducer you should get properties off the `payload` property. (#63)

@@ -1,11 +0,23 @@

"use strict";
'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var deepEqual = require('deep-equal');
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.routeReducer = exports.UPDATE_PATH = undefined;
exports.pushPath = pushPath;
exports.replacePath = replacePath;
exports.syncReduxAndRouter = syncReduxAndRouter;
var _deepEqual = require('deep-equal');
var _deepEqual2 = _interopRequireDefault(_deepEqual);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// Constants
var INIT_PATH = "@@router/INIT_PATH";
var UPDATE_PATH = "@@router/UPDATE_PATH";
var INIT_PATH = '@@router/INIT_PATH';
var UPDATE_PATH = exports.UPDATE_PATH = '@@router/UPDATE_PATH';
var SELECT_STATE = function SELECT_STATE(state) {

@@ -92,5 +104,16 @@ return state.routing;

function locationsAreEqual(a, b) {
return a != null && b != null && a.path === b.path && deepEqual(a.state, b.state);
return a != null && b != null && a.path === b.path && (0, _deepEqual2.default)(a.state, b.state);
}
function createPath(location) {
var pathname = location.pathname;
var search = location.search;
var hash = location.hash;
var result = pathname;
if (search) result += search;
if (hash) result += hash;
return result;
}
function syncReduxAndRouter(history, store) {

@@ -113,3 +136,3 @@ var selectRouterState = arguments.length <= 2 || arguments[2] === undefined ? SELECT_STATE : arguments[2];

if (!getRouterState()) {
throw new Error("Cannot sync router: route state does not exist. Did you " + "install the routing reducer?");
throw new Error('Cannot sync router: route state does not exist. Did you ' + 'install the routing reducer?');
}

@@ -119,3 +142,3 @@

var route = {
path: history.createPath(location),
path: createPath(location),
state: location.state

@@ -174,8 +197,2 @@ };

module.exports = {
UPDATE_PATH: UPDATE_PATH,
pushPath: pushPath,
replacePath: replacePath,
syncReduxAndRouter: syncReduxAndRouter,
routeReducer: update
};
exports.routeReducer = update;
{
"name": "redux-simple-router",
"version": "1.0.0",
"version": "1.0.1",
"description": "Ruthlessly simple bindings to keep react-router and redux in sync",

@@ -16,2 +16,3 @@ "main": "lib/index",

"build": "mkdir -p lib && babel ./src/index.js --out-file ./lib/index.js",
"lint": "eslint src test",
"test": "npm run test:node && npm run test:browser",

@@ -38,5 +39,8 @@ "test:node": "mocha --compilers js:babel-core/register --recursive ./test/node",

"babel-core": "^6.2.1",
"babel-eslint": "^4.1.6",
"babel-loader": "^6.2.0",
"babel-plugin-transform-object-assign": "^6.0.14",
"babel-preset-es2015": "^6.1.2",
"eslint": "^1.10.3",
"eslint-config-rackt": "^1.1.1",
"expect": "^1.13.0",

@@ -43,0 +47,0 @@ "history": "^1.13.1",

@@ -1,8 +0,8 @@

const deepEqual = require('deep-equal');
import deepEqual from 'deep-equal'
// Constants
const INIT_PATH = "@@router/INIT_PATH";
const UPDATE_PATH = "@@router/UPDATE_PATH";
const SELECT_STATE = state => state.routing;
const INIT_PATH = '@@router/INIT_PATH'
export const UPDATE_PATH = '@@router/UPDATE_PATH'
const SELECT_STATE = state => state.routing

@@ -20,6 +20,6 @@ // Action creators

}
};
}
}
function pushPath(path, state, { avoidRouterUpdate = false } = {}) {
export function pushPath(path, state, { avoidRouterUpdate = false } = {}) {
return {

@@ -33,6 +33,6 @@ type: UPDATE_PATH,

}
};
}
}
function replacePath(path, state, { avoidRouterUpdate = false } = {}) {
export function replacePath(path, state, { avoidRouterUpdate = false } = {}) {
return {

@@ -56,3 +56,3 @@ type: UPDATE_PATH,

replace: false
};
}

@@ -66,5 +66,5 @@ function update(state=initialState, { type, payload }) {

replace: payload.replace
});
})
}
return state;
return state
}

@@ -75,8 +75,18 @@

function locationsAreEqual(a, b) {
return a != null && b != null && a.path === b.path && deepEqual(a.state, b.state);
return a != null && b != null && a.path === b.path && deepEqual(a.state, b.state)
}
function syncReduxAndRouter(history, store, selectRouterState = SELECT_STATE) {
const getRouterState = () => selectRouterState(store.getState());
function createPath(location) {
const { pathname, search, hash } = location
let result = pathname
if (search)
result += search
if (hash)
result += hash
return result
}
export function syncReduxAndRouter(history, store, selectRouterState = SELECT_STATE) {
const getRouterState = () => selectRouterState(store.getState())
// To properly handle store updates we need to track the last route.

@@ -89,9 +99,9 @@ // This route contains a `changeId` which is updated on every

// reloads the entire app state such as redux devtools.
let lastRoute = undefined;
let lastRoute = undefined
if(!getRouterState()) {
throw new Error(
"Cannot sync router: route state does not exist. Did you " +
"install the routing reducer?"
);
'Cannot sync router: route state does not exist. Did you ' +
'install the routing reducer?'
)
}

@@ -101,5 +111,5 @@

const route = {
path: history.createPath(location),
path: createPath(location),
state: location.state
};
}

@@ -122,19 +132,19 @@ if (!lastRoute) {

replace: false
};
}
// Also set `lastRoute` so that the store subscriber doesn't
// trigger an unnecessary `pushState` on load
lastRoute = initialState;
lastRoute = initialState
store.dispatch(initPath(route.path, route.state));
store.dispatch(initPath(route.path, route.state))
} else if(!locationsAreEqual(getRouterState(), route)) {
// The above check avoids dispatching an action if the store is
// already up-to-date
const method = location.action === 'REPLACE' ? replacePath : pushPath;
store.dispatch(method(route.path, route.state, { avoidRouterUpdate: true }));
const method = location.action === 'REPLACE' ? replacePath : pushPath
store.dispatch(method(route.path, route.state, { avoidRouterUpdate: true }))
}
});
})
const unsubscribeStore = store.subscribe(() => {
let routing = getRouterState();
let routing = getRouterState()

@@ -146,21 +156,15 @@ // Only trigger history update if this is a new change or the

lastRoute = routing;
const method = routing.replace ? 'replaceState' : 'pushState';
history[method](routing.state, routing.path);
lastRoute = routing
const method = routing.replace ? 'replaceState' : 'pushState'
history[method](routing.state, routing.path)
}
});
})
return function unsubscribe() {
unsubscribeHistory();
unsubscribeStore();
};
unsubscribeHistory()
unsubscribeStore()
}
}
module.exports = {
UPDATE_PATH,
pushPath,
replacePath,
syncReduxAndRouter,
routeReducer: update
};
export { update as routeReducer }

@@ -1,5 +0,5 @@

const { createHashHistory, createHistory } = require('history');
const createTests = require('../createTests.js');
import { createHashHistory, createHistory } from 'history'
import createTests from '../createTests.js'
createTests(createHashHistory, 'Hash History', () => window.location = '#/');
createTests(createHistory, 'Browser History', () => window.history.replaceState(null, null, '/'));
createTests(createHashHistory, 'Hash History', () => window.location = '#/')
createTests(createHistory, 'Browser History', () => window.history.replaceState(null, null, '/'))

@@ -1,7 +0,10 @@

const expect = require('expect');
const { pushPath, replacePath, UPDATE_PATH, routeReducer, syncReduxAndRouter } = require('../src/index');
const { createStore, combineReducers, compose } = require('redux');
const { devTools } = require('redux-devtools');
const { ActionCreators } = require('redux-devtools/lib/devTools');
/*eslint-env mocha */
import expect from 'expect'
import { pushPath, replacePath, UPDATE_PATH, routeReducer, syncReduxAndRouter } from '../src/index'
import { createStore, combineReducers, compose } from 'redux'
import { devTools } from 'redux-devtools'
import { ActionCreators } from 'redux-devtools/lib/devTools'
import { useBasename } from 'history'
expect.extend({

@@ -14,10 +17,10 @@ toContainRoute({

}) {
const routing = this.actual.getState().routing;
const routing = this.actual.getState().routing
expect(routing.path).toEqual(path);
expect(routing.state).toEqual(state);
expect(routing.replace).toEqual(replace);
expect(routing.path).toEqual(path)
expect(routing.state).toEqual(state)
expect(routing.replace).toEqual(replace)
if (changeId !== undefined) {
expect(routing.changeId).toEqual(changeId);
expect(routing.changeId).toEqual(changeId)
}

@@ -30,9 +33,9 @@ }

routing: routeReducer
}));
const history = createHistory();
const unsubscribe = syncReduxAndRouter(history, store);
return { history, store, unsubscribe };
}))
const history = createHistory()
const unsubscribe = syncReduxAndRouter(history, store)
return { history, store, unsubscribe }
}
const defaultReset = () => {};
const defaultReset = () => {}

@@ -42,3 +45,3 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) {

beforeEach(reset);
beforeEach(reset)

@@ -55,3 +58,3 @@ describe('pushPath', () => {

}
});
})

@@ -66,5 +69,5 @@ expect(pushPath('/foo', undefined, { avoidRouterUpdate: true })).toEqual({

}
});
});
});
})
})
})

@@ -81,3 +84,3 @@ describe('replacePath', () => {

}
});
})

@@ -92,3 +95,3 @@ expect(replacePath('/foo', undefined, { avoidRouterUpdate: true })).toEqual({

}
});
})

@@ -103,5 +106,5 @@ expect(replacePath('/foo', undefined, { avoidRouterUpdate: false })).toEqual({

}
});
});
});
})
})
})

@@ -112,3 +115,3 @@ describe('routeReducer', () => {

changeId: 1
};
}

@@ -127,4 +130,4 @@ it('updates the path', () => {

changeId: 2
});
});
})
})

@@ -144,4 +147,4 @@ it('respects replace', () => {

changeId: 2
});
});
})
})

@@ -161,5 +164,5 @@ it('respects `avoidRouterUpdate` flag', () => {

changeId: 1
});
});
});
})
})
})

@@ -171,93 +174,93 @@ // To ensure that "Revert" and toggling actions work as expected in

describe('devtools', () => {
let history, store, devToolsStore, unsubscribe;
let history, store, devToolsStore, unsubscribe
beforeEach(() => {
history = createHistory();
const finalCreateStore = compose(devTools())(createStore);
history = createHistory()
const finalCreateStore = compose(devTools())(createStore)
store = finalCreateStore(combineReducers({
routing: routeReducer
}));
devToolsStore = store.devToolsStore;
}))
devToolsStore = store.devToolsStore
// Set initial URL before syncing
history.pushState(null, '/foo');
history.pushState(null, '/foo')
unsubscribe = syncReduxAndRouter(history, store);
});
unsubscribe = syncReduxAndRouter(history, store)
})
afterEach(() => {
unsubscribe();
});
unsubscribe()
})
it('resets to the initial url', () => {
let currentPath;
let currentPath
const historyUnsubscribe = history.listen(location => {
currentPath = location.pathname;
});
currentPath = location.pathname
})
history.pushState(null, '/bar');
store.dispatch(pushPath('/baz'));
history.pushState(null, '/bar')
store.dispatch(pushPath('/baz'))
// By calling reset we expect DevTools to re-play the initial state
// and the history to update to the initial path
devToolsStore.dispatch(ActionCreators.reset());
devToolsStore.dispatch(ActionCreators.reset())
expect(store.getState().routing.path).toEqual('/foo');
expect(currentPath).toEqual('/foo');
expect(store.getState().routing.path).toEqual('/foo')
expect(currentPath).toEqual('/foo')
historyUnsubscribe();
});
historyUnsubscribe()
})
it('handles toggle after store change', () => {
let currentPath;
let currentPath
const historyUnsubscribe = history.listen(location => {
currentPath = location.pathname;
});
currentPath = location.pathname
})
// DevTools action #2
history.pushState(null, '/foo2');
history.pushState(null, '/foo2')
// DevTools action #3
history.pushState(null, '/foo3');
history.pushState(null, '/foo3')
// When we toggle an action, the devtools will revert the action
// and we therefore expect the history to update to the previous path
devToolsStore.dispatch(ActionCreators.toggleAction(3));
expect(currentPath).toEqual('/foo2');
devToolsStore.dispatch(ActionCreators.toggleAction(3))
expect(currentPath).toEqual('/foo2')
historyUnsubscribe();
});
historyUnsubscribe()
})
it('handles toggle after store change', () => {
let currentPath;
let currentPath
const historyUnsubscribe = history.listen(location => {
currentPath = location.pathname;
});
currentPath = location.pathname
})
// DevTools action #2
store.dispatch(pushPath('/foo2'));
store.dispatch(pushPath('/foo2'))
// DevTools action #3
store.dispatch(pushPath('/foo3'));
store.dispatch(pushPath('/foo3'))
// When we toggle an action, the devtools will revert the action
// and we therefore expect the history to update to the previous path
devToolsStore.dispatch(ActionCreators.toggleAction(3));
expect(currentPath).toEqual('/foo2');
devToolsStore.dispatch(ActionCreators.toggleAction(3))
expect(currentPath).toEqual('/foo2')
historyUnsubscribe();
});
});
historyUnsubscribe()
})
})
describe('syncReduxAndRouter', () => {
let history, store, unsubscribe;
let history, store, unsubscribe
beforeEach(() => {
let synced = createSyncedHistoryAndStore(createHistory);
history = synced.history;
store = synced.store;
unsubscribe = synced.unsubscribe;
});
let synced = createSyncedHistoryAndStore(createHistory)
history = synced.history
store = synced.store
unsubscribe = synced.unsubscribe
})
afterEach(() => {
unsubscribe();
});
unsubscribe()
})

@@ -267,5 +270,5 @@ it('syncs router -> redux', () => {

path: '/'
});
})
history.pushState(null, '/foo');
history.pushState(null, '/foo')
expect(store).toContainRoute({

@@ -275,5 +278,5 @@ path: '/foo',

state: null
});
})
history.pushState({ bar: 'baz' }, '/foo');
history.pushState({ bar: 'baz' }, '/foo')
expect(store).toContainRoute({

@@ -283,5 +286,5 @@ path: '/foo',

state: { bar: 'baz' }
});
})
history.replaceState(null, '/bar');
history.replaceState(null, '/bar')
expect(store).toContainRoute({

@@ -291,5 +294,5 @@ path: '/bar',

state: null
});
})
history.pushState(null, '/bar');
history.pushState(null, '/bar')
expect(store).toContainRoute({

@@ -299,5 +302,5 @@ path: '/bar',

state: null
});
})
history.pushState(null, '/bar?query=1');
history.pushState(null, '/bar?query=1')
expect(store).toContainRoute({

@@ -307,5 +310,5 @@ path: '/bar?query=1',

state: null
});
})
history.replaceState({ bar: 'baz' }, '/bar?query=1');
history.replaceState({ bar: 'baz' }, '/bar?query=1')
expect(store).toContainRoute({

@@ -315,5 +318,5 @@ path: '/bar?query=1',

state: { bar: 'baz' }
});
})
history.pushState({ bar: 'baz' }, '/bar?query=1#hash=2');
history.pushState({ bar: 'baz' }, '/bar?query=1#hash=2')
expect(store).toContainRoute({

@@ -323,4 +326,4 @@ path: '/bar?query=1#hash=2',

state: { bar: 'baz' }
});
});
})
})

@@ -332,5 +335,5 @@ it('syncs redux -> router', () => {

state: undefined
});
})
store.dispatch(pushPath('/foo'));
store.dispatch(pushPath('/foo'))
expect(store).toContainRoute({

@@ -340,5 +343,5 @@ path: '/foo',

state: undefined
});
})
store.dispatch(pushPath('/foo', { bar: 'baz' }));
store.dispatch(pushPath('/foo', { bar: 'baz' }))
expect(store).toContainRoute({

@@ -348,5 +351,5 @@ path: '/foo',

state: { bar: 'baz' }
});
})
store.dispatch(replacePath('/bar', { bar: 'foo' }));
store.dispatch(replacePath('/bar', { bar: 'foo' }))
expect(store).toContainRoute({

@@ -356,5 +359,5 @@ path: '/bar',

state: { bar: 'foo' }
});
})
store.dispatch(pushPath('/bar'));
store.dispatch(pushPath('/bar'))
expect(store).toContainRoute({

@@ -364,5 +367,5 @@ path: '/bar',

state: undefined
});
})
store.dispatch(pushPath('/bar?query=1'));
store.dispatch(pushPath('/bar?query=1'))
expect(store).toContainRoute({

@@ -372,5 +375,5 @@ path: '/bar?query=1',

state: undefined
});
})
store.dispatch(pushPath('/bar?query=1#hash=2'));
store.dispatch(pushPath('/bar?query=1#hash=2'))
expect(store).toContainRoute({

@@ -380,39 +383,23 @@ path: '/bar?query=1#hash=2',

state: undefined
});
});
})
})
it('updates the router even if path is the same', () => {
expect(store).toContainRoute({
path: '/',
changeId: 1,
replace: false,
state: undefined
});
const updates = []
const historyUnsubscribe = history.listen(location => {
updates.push(location.pathname)
})
store.dispatch(pushPath('/foo'));
expect(store).toContainRoute({
path: '/foo',
changeId: 2,
replace: false,
state: undefined
});
store.dispatch(pushPath('/foo'))
store.dispatch(pushPath('/foo'))
store.dispatch(replacePath('/foo'))
store.dispatch(pushPath('/foo'));
expect(store).toContainRoute({
path: '/foo',
changeId: 3,
replace: false,
state: undefined
});
expect(updates).toEqual([ '/', '/foo', '/foo', '/foo' ])
store.dispatch(replacePath('/foo'));
expect(store).toContainRoute({
path: '/foo',
changeId: 4,
replace: true,
state: undefined
});
});
historyUnsubscribe()
})
it('does not update the router for other state changes', () => {
const state = store.getState()
store.dispatch({

@@ -425,22 +412,10 @@ type: 'RANDOM_ACTION',

}
});
})
expect(store).toContainRoute({
path: '/',
changeId: 1,
replace: false,
state: undefined
});
});
expect(state).toEqual(store.getState())
})
it('only updates the router once when dispatching from `listenBefore`', () => {
expect(store).toContainRoute({
path: '/',
changeId: 1,
replace: false,
state: undefined
});
history.listenBefore(location => {
expect(location.pathname).toEqual('/foo');
expect(location.pathname).toEqual('/foo')
store.dispatch({

@@ -453,124 +428,43 @@ type: 'RANDOM_ACTION',

}
});
});
})
})
store.dispatch(pushPath('/foo'));
expect(store).toContainRoute({
path: '/foo',
changeId: 2,
replace: false,
state: undefined
});
});
const updates = []
history.listen(location => {
updates.push(location.pathname)
})
it('does not unnecessarily update the store', () => {
const updates = [];
store.dispatch(pushPath('/foo'))
const unsubscribeFromStore = store.subscribe(() => {
updates.push(store.getState())
});
expect(updates).toEqual([ '/', '/foo' ])
})
store.dispatch(pushPath('/foo'));
store.dispatch(pushPath('/foo'));
store.dispatch(pushPath('/foo', { bar: 'baz' }));
history.pushState({ foo: 'bar' }, '/foo');
store.dispatch(replacePath('/bar'));
store.dispatch(replacePath('/bar', { bar: 'foo' }));
unsubscribeFromStore();
expect(updates.length).toBe(6);
expect(updates).toEqual([
{
routing: {
changeId: 2,
path: '/foo',
state: undefined,
replace: false
}
},
{
routing: {
changeId: 3,
path: '/foo',
state: undefined,
replace: false
}
},
{
routing: {
changeId: 4,
path: '/foo',
state: { bar: 'baz' },
replace: false
}
},
{
routing: {
changeId: 4,
path: '/foo',
state: { foo: 'bar' },
replace: true
}
},
{
routing: {
changeId: 5,
path: '/bar',
state: undefined,
replace: true
}
},
{
routing: {
changeId: 6,
path: '/bar',
state: { bar: 'foo' },
replace: true
}
}
]);
});
it('allows updating the route from within `listenBefore`', () => {
expect(store).toContainRoute({
path: '/'
});
history.listenBefore(location => {
if(location.pathname === '/foo') {
expect(store).toContainRoute({
path: '/foo',
changeId: 2,
replace: false,
state: undefined
});
store.dispatch(pushPath('/bar'));
store.dispatch(pushPath('/bar'))
}
else if(location.pathname === '/replace') {
expect(store).toContainRoute({
path: '/replace',
changeId: 4,
replace: false,
state: { bar: 'baz' }
});
store.dispatch(replacePath('/baz', { foo: 'bar' }));
store.dispatch(replacePath('/baz', { foo: 'bar' }))
}
});
})
store.dispatch(pushPath('/foo'));
const updates = []
history.listen(location => {
updates.push(location.pathname)
})
store.dispatch(pushPath('/foo'))
expect(store).toContainRoute({
path: '/bar',
changeId: 3,
replace: false,
state: undefined
});
path: '/bar'
})
store.dispatch(pushPath('/replace', { bar: 'baz' }));
store.dispatch(pushPath('/replace', { bar: 'baz' }))
expect(store).toContainRoute({
path: '/baz',
changeId: 5,
replace: true,
state: { foo: 'bar' }
});
state: { foo: 'bar' },
replace: true
})
expect(updates).toEqual([ '/', '/bar', '/baz' ])
})

@@ -581,8 +475,8 @@

notRouting: routeReducer
}));
const history = createHistory();
}))
const history = createHistory()
expect(
() => syncReduxAndRouter(history, store)
).toThrow(/Cannot sync router: route state does not exist/);
});
).toThrow(/Cannot sync router: route state does not exist/)
})

@@ -592,8 +486,8 @@ it('accepts custom selectRouterState', () => {

notRouting: routeReducer
}));
const history = createHistory();
}))
const history = createHistory()
syncReduxAndRouter(history, store, state => state.notRouting)
history.pushState(null, '/bar');
expect(store.getState().notRouting.path).toEqual('/bar');
});
history.pushState(null, '/bar')
expect(store.getState().notRouting.path).toEqual('/bar')
})

@@ -603,35 +497,77 @@ it('returns unsubscribe to stop listening to history and store', () => {

routing: routeReducer
}));
const history = createHistory();
}))
const history = createHistory()
const unsubscribe = syncReduxAndRouter(history, store)
history.pushState(null, '/foo');
history.pushState(null, '/foo')
expect(store).toContainRoute({
path: '/foo'
});
})
store.dispatch(pushPath('/bar'));
store.dispatch(pushPath('/bar'))
expect(store).toContainRoute({
path: '/bar',
changeId: 2,
replace: false,
state: undefined
});
path: '/bar'
})
unsubscribe();
unsubscribe()
history.pushState(null, '/foo');
history.pushState(null, '/foo')
expect(store).toContainRoute({
path: '/bar'
});
})
history.listenBefore(location => {
history.listenBefore(() => {
throw new Error()
});
})
expect(
() => store.dispatch(pushPath('/foo'))
).toNotThrow();
});
});
});
).toNotThrow()
})
it('only triggers history once when updating path via store', () => {
const updates = []
const historyUnsubscribe = history.listen(location => {
updates.push(location.pathname)
})
store.dispatch(pushPath('/bar'))
store.dispatch(pushPath('/baz'))
expect(updates).toEqual([ '/', '/bar', '/baz' ])
historyUnsubscribe()
})
it('only triggers store once when updating path via store', () => {
const updates = []
const storeUnsubscribe = store.subscribe(() => {
updates.push(store.getState().routing.path)
})
store.dispatch(pushPath('/bar'))
store.dispatch(pushPath('/baz'))
store.dispatch(replacePath('/foo'))
expect(updates).toEqual([ '/bar', '/baz', '/foo' ])
storeUnsubscribe()
})
})
it('handles basename history option', () => {
const store = createStore(combineReducers({
routing: routeReducer
}))
const history = useBasename(createHistory)({ basename:'/foobar' })
syncReduxAndRouter(history, store)
store.dispatch(pushPath('/bar'))
expect(store).toContainRoute({
path: '/bar'
})
history.pushState(undefined, '/baz')
expect(store).toContainRoute({
path: '/baz'
})
})
})
}

@@ -1,4 +0,4 @@

const { createMemoryHistory } = require('history');
const createTests = require('../createTests.js');
import { createMemoryHistory } from 'history'
import createTests from '../createTests.js'
createTests(createMemoryHistory, 'Memory History');
createTests(createMemoryHistory, 'Memory History')
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc