Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Export action creators in namespace. Add go, goBack, goForward #149

Merged
merged 2 commits into from
Jan 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ function transition(method) {
})
}

export const push = transition('push')
export const replace = transition('replace')

// TODO: Add go, goBack, goForward.
export const routeActions = {
push: transition('push'),
replace: transition('replace'),
go: transition('go'),
goBack: transition('goBack'),
goForward: transition('goForward')
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably add go, goBack, and goForward? They'll just work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 😄


function updateLocation(location) {
return {
Expand Down
92 changes: 64 additions & 28 deletions test/createTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import expect from 'expect'
import {
push, replace, TRANSITION, UPDATE_LOCATION, routeReducer, syncHistory
routeActions, TRANSITION, UPDATE_LOCATION, routeReducer, syncHistory
} from '../src/index'
import { applyMiddleware, createStore, combineReducers, compose } from 'redux'
import { devTools } from 'redux-devtools'
Expand Down Expand Up @@ -43,47 +43,83 @@ function createSyncedHistoryAndStore(createHistory) {

const defaultReset = () => {}

const { push, replace, go, goBack, goForward } = routeActions

module.exports = function createTests(createHistory, name, reset = defaultReset) {
describe(name, () => {

beforeEach(reset)

describe('push', () => {
it('creates actions', () => {
expect(push('/foo')).toEqual({
type: TRANSITION,
method: 'push',
arg: '/foo'
describe('routeActions', () => {

describe('push', () => {
it('creates actions', () => {
expect(push('/foo')).toEqual({
type: TRANSITION,
method: 'push',
arg: '/foo'
})

expect(push({ pathname: '/foo', state: { the: 'state' } })).toEqual({
type: TRANSITION,
method: 'push',
arg: {
pathname: '/foo',
state: { the: 'state' }
}
})
})
})

expect(push({ pathname: '/foo', state: { the: 'state' } })).toEqual({
type: TRANSITION,
method: 'push',
arg: {
pathname: '/foo',
state: { the: 'state' }
}
describe('replace', () => {
it('creates actions', () => {
expect(replace('/foo')).toEqual({
type: TRANSITION,
method: 'replace',
arg: '/foo'
})

expect(replace({ pathname: '/foo', state: { the: 'state' } })).toEqual({
type: TRANSITION,
method: 'replace',
arg: {
pathname: '/foo',
state: { the: 'state' }
}
})
})
})
})

describe('replace', () => {
it('creates actions', () => {
expect(replace('/foo')).toEqual({
type: TRANSITION,
method: 'replace',
arg: '/foo'
describe('go', () => {
it('creates actions', () => {
expect(go(1)).toEqual({
type: TRANSITION,
method: 'go',
arg: 1
})
})
})

expect(replace({ pathname: '/foo', state: { the: 'state' } })).toEqual({
type: TRANSITION,
method: 'replace',
arg: {
pathname: '/foo',
state: { the: 'state' }
}
describe('goBack', () => {
it('creates actions', () => {
expect(goBack()).toEqual({
type: TRANSITION,
method: 'goBack',
arg: undefined
})
})
})

describe('goForward', () => {
it('creates actions', () => {
expect(goForward()).toEqual({
type: TRANSITION,
method: 'goForward',
arg: undefined
})
})
})

})

describe('routeReducer', () => {
Expand Down