Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
fix inadvertent non-running of saga tests and integration tests in karma
Browse files Browse the repository at this point in the history
also, fix state munging in reducer test, eliminate repeated code,
increase coverage
  • Loading branch information
cellog committed Apr 14, 2017
1 parent cbb2735 commit 685f141
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 29 deletions.
4 changes: 2 additions & 2 deletions karma-common.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ module.exports = function (config, extraoptions) {

files: [
'../../node_modules/babel-polyfill/dist/polyfill.js',
'../*.test.js'
'../**/*.test.js'
],

preprocessors: {
'../*.test.js': ['webpack'],
'../**/*.test.js': ['webpack'],
},

webpack,
Expand Down
26 changes: 7 additions & 19 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ export function addRoute(params) {
}
}

export function batchRoutes(routes) {
export function batch(routes, type) {
return {
type: types.BATCH_ROUTES,
type,
payload: {
ids: routes.map(r => r.name),
routes: routes.reduce(
Expand All @@ -89,6 +89,10 @@ export function batchRoutes(routes) {
}
}

export function batchRoutes(routes) {
return batch(routes, types.BATCH_ROUTES)
}

export function removeRoute(name) {
return {
type: types.REMOVE_ROUTE,
Expand All @@ -97,23 +101,7 @@ export function removeRoute(name) {
}

export function batchRemoveRoutes(routes) {
return {
type: types.BATCH_REMOVE_ROUTES,
payload: {
ids: routes.map(r => r.name),
routes: routes.reduce(
(defs, r) => ({
...defs,
[r.name]: {
parent: r.parent,
...r,
params: {},
state: {}
}
}), {}
)
}
}
return batch(routes, types.BATCH_REMOVE_ROUTES)
}

export function setParamsAndState(details, params, state) {
Expand Down
7 changes: 7 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,11 @@ describe('react-redux-saga-router', () => {
}
})
})
it('setServer', () => {
expect(index.options.server).is.false
index.setServer()
expect(index.options.server).is.true
index.setServer(false)
expect(index.options.server).is.false
})
})
16 changes: 8 additions & 8 deletions test/reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as actions from '../src/actions'

describe('react-redux-saga-router reducer', () => {
it('ROUTE', () => {
const state = reducer()
const state = { ...reducer() }
expect(reducer(state, actions.route({
pathname: '',
search: '',
Expand All @@ -23,14 +23,14 @@ describe('react-redux-saga-router reducer', () => {
})
})
it('MATCH_ROUTES', () => {
const state = reducer()
const state = { ...reducer() }
expect(reducer(state, actions.matchRoutes(['foo']))).eqls({
...state,
matchedRoutes: ['foo']
})
})
it('SET_PARAMS', () => {
const state = reducer()
const state = { ...reducer() }
state.routes = {
ids: ['foo', 'bar'],
routes: {
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('react-redux-saga-router reducer', () => {
})
})
it('EDIT_ROUTE', () => {
const state = reducer()
const state = { ...reducer() }
state.routes = {
ids: ['foo', 'bar'],
routes: {
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('react-redux-saga-router reducer', () => {
})
})
it('BATCH_ROUTE', () => {
const state = reducer()
const state = { ...reducer() }
state.routes = {
ids: ['foo', 'bar'],
routes: {
Expand Down Expand Up @@ -190,12 +190,12 @@ describe('react-redux-saga-router reducer', () => {
expect(reducer(state, action)).eqls(newstate)
})
it('REMOVE_ROUTE', () => {
const start = reducer()
const start = { ...reducer() }
const state = reducer(start, actions.addRoute({ name: 'hi', path: '/hi/:there' }))
expect(reducer(state, actions.removeRoute('hi'))).eqls(start)
})
it('BATCH_REMOVE_ROUTES', () => {
const fstate = reducer(undefined, actions.batchRoutes([
const fstate = { ...reducer(undefined, actions.batchRoutes([
{
name: 'fer',
path: '/fer',
Expand All @@ -208,7 +208,7 @@ describe('react-redux-saga-router reducer', () => {
params: {},
state: {}
}
]))
])) }
expect(reducer(fstate, actions.batchRemoveRoutes([
{
name: 'fer',
Expand Down

0 comments on commit 685f141

Please sign in to comment.