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

Commit 2b177f5

Browse files
committed
Add middleware test. Reorg test suite.
1 parent def06ff commit 2b177f5

File tree

10 files changed

+47
-14
lines changed

10 files changed

+47
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"build": "mkdir -p lib && babel ./src -d lib",
2020
"lint": "eslint examples src test",
2121
"test": "npm run lint && npm run test:node && npm run test:browser",
22-
"test:node": "mocha --compilers js:babel-register --recursive ./test/node",
22+
"test:node": "mocha --compilers js:babel-register --recursive ./test/*.spec.js",
2323
"test:browser": "karma start",
2424
"test:cov": "npm run test:cov:browser && npm run test:cov:node && npm run test:cov:report",
2525
"test:cov:node": "babel-node $(npm bin)/isparta cover $(npm bin)/_mocha report --dir ./coverage/node-coverage -- --recursive ./test/node",

src/middleware.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import UPDATE_LOCATION from './actions'
1+
import { UPDATE_LOCATION } from './actions'
22

33
/**
44
* This middleware captures UPDATE_LOCATION actions to redirect to the

test/.eslintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"env": {
3+
"mocha": true
4+
}
5+
}

test/createTests.js renamed to test/_createSyncTest.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/*eslint-env mocha */
2-
31
import expect from 'expect'
42

53
import { createStore, combineReducers } from 'redux'

test/node/actions.js renamed to test/actions.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
/* eslint-env mocha */
2-
31
import expect from 'expect'
42

53
import {
64
UPDATE_LOCATION,
75
push, replace, go, goBack, goForward
8-
} from '../../src/actions'
6+
} from '../src/actions'
97

108
describe('routeActions', () => {
119

test/browser/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'babel-polyfill'
22

33
import { hashHistory, browserHistory } from 'react-router'
4-
import createTests from '../createTests.js'
4+
import createTests from '../_createSyncTest'
55

66
createTests(hashHistory, 'Hash History', () => window.location = '#/')
77
createTests(browserHistory, 'Browser History', () => window.history.replaceState(null, null, '/'))

test/middleware.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import expect, { createSpy } from 'expect'
2+
3+
import { push, replace } from '../src/actions'
4+
import routerMiddleware from '../src/middleware'
5+
6+
describe('routerMiddleware', () => {
7+
let history, next, dispatch
8+
9+
beforeEach(() => {
10+
history = {
11+
push: createSpy(),
12+
replace: createSpy()
13+
}
14+
next = createSpy()
15+
16+
dispatch = routerMiddleware(history)()(next)
17+
})
18+
19+
20+
it('calls the appropriate history method', () => {
21+
dispatch(push('/foo'))
22+
expect(history.push).toHaveBeenCalled()
23+
24+
dispatch(replace('/foo'))
25+
expect(history.replace).toHaveBeenCalled()
26+
27+
expect(next).toNotHaveBeenCalled()
28+
})
29+
30+
it('ignores other actions', () => {
31+
dispatch({ type: 'FOO' })
32+
expect(next).toHaveBeenCalled()
33+
})
34+
})

test/node/reducer.js renamed to test/reducer.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
/* eslint-env mocha */
2-
31
import expect from 'expect'
42

5-
import { LOCATION_CHANGE, routerReducer } from '../../src/reducer'
3+
import { LOCATION_CHANGE, routerReducer } from '../src/reducer'
64

75
describe('routerReducer', () => {
86
const state = {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { createMemoryHistory } from 'react-router'
2-
import createTests from '../createTests.js'
2+
import createTests from './_createSyncTest'
33

44
createTests(createMemoryHistory(), 'Memory History')

tests.webpack.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
const browserContext = require.context('./test/browser', true, /\.js$/);
2-
browserContext.keys().forEach(browserContext);
1+
const browserContext = require.context('./test/browser')
2+
browserContext.keys().forEach(browserContext)

0 commit comments

Comments
 (0)