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

Commit 9b2dc36

Browse files
committed
Don't leave test side effects with history singltons.
1 parent 0b7b322 commit 9b2dc36

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"eslint-config-rackt": "^1.1.1",
5050
"eslint-plugin-react": "^3.15.0",
5151
"expect": "^1.13.0",
52+
"history": "^2.0.0",
5253
"isparta": "^4.0.0",
5354
"isparta-loader": "^2.0.0",
5455
"karma": "^0.13.3",
@@ -63,7 +64,6 @@
6364
"karma-webpack": "^1.7.0",
6465
"mocha": "^2.3.4",
6566
"react": "^0.14.3",
66-
"react-router": "^2.0.0-rc5",
6767
"redux": "^3.0.4",
6868
"redux-devtools": "^3.0.0",
6969
"redux-devtools-dock-monitor": "^1.0.1",

test/_createSyncTest.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ expect.extend({
1212
search = '',
1313
hash = '',
1414
state = null,
15-
query = {},
15+
query,
1616
action = 'PUSH'
1717
}) {
1818
const { locationBeforeTransitions } = this.actual.getState().routing
@@ -28,19 +28,19 @@ expect.extend({
2828
})
2929

3030

31-
function createSyncedHistoryAndStore(testHistory) {
31+
function createSyncedHistoryAndStore(originalHistory) {
3232

3333
const store = createStore(combineReducers({
3434
routing: routerReducer
3535
}))
36-
const history = syncHistoryWithStore(testHistory, store)
36+
const history = syncHistoryWithStore(originalHistory, store)
3737

3838
return { history, store }
3939
}
4040

4141
const defaultReset = () => {}
4242

43-
export default function createTests(testHistory, name, reset = defaultReset) {
43+
export default function createTests(createHistory, name, reset = defaultReset) {
4444
describe(name, () => {
4545

4646
beforeEach(reset)
@@ -49,7 +49,7 @@ export default function createTests(testHistory, name, reset = defaultReset) {
4949
let history, store
5050

5151
beforeEach(() => {
52-
let synced = createSyncedHistoryAndStore(testHistory)
52+
let synced = createSyncedHistoryAndStore(createHistory())
5353
history = synced.history
5454
store = synced.store
5555
})
@@ -58,7 +58,7 @@ export default function createTests(testHistory, name, reset = defaultReset) {
5858
history.unsubscribe()
5959
})
6060

61-
it('syncs router -> redux', () => {
61+
it('syncs history -> redux', () => {
6262
expect(store).toContainLocation({
6363
pathname: '/',
6464
action: 'POP'
@@ -91,8 +91,7 @@ export default function createTests(testHistory, name, reset = defaultReset) {
9191
history.push('/bar?query=1')
9292
expect(store).toContainLocation({
9393
pathname: '/bar',
94-
search: '?query=1',
95-
query: { query: '1' }
94+
search: '?query=1'
9695
})
9796

9897
history.push('/bar#baz')
@@ -109,7 +108,6 @@ export default function createTests(testHistory, name, reset = defaultReset) {
109108
expect(store).toContainLocation({
110109
pathname: '/bar',
111110
search: '?query=1',
112-
query: { query: '1' },
113111
state: { bar: 'baz' },
114112
action: 'REPLACE'
115113
})
@@ -123,7 +121,6 @@ export default function createTests(testHistory, name, reset = defaultReset) {
123121
expect(store).toContainLocation({
124122
pathname: '/bar',
125123
search: '?query=1',
126-
query: { query: '1' },
127124
hash: '#hash=2',
128125
state: { bar: 'baz' },
129126
action: 'REPLACE'
@@ -163,11 +160,13 @@ export default function createTests(testHistory, name, reset = defaultReset) {
163160
})
164161

165162
describe('Redux DevTools', () => {
166-
let history, store, devToolsStore
163+
let originalHistory, history, store, devToolsStore
167164

168165
beforeEach(() => {
166+
originalHistory = createHistory()
167+
169168
// Set initial URL before syncing
170-
testHistory.push('/foo')
169+
originalHistory.push('/foo')
171170

172171
store = createStore(
173172
combineReducers({
@@ -177,7 +176,7 @@ export default function createTests(testHistory, name, reset = defaultReset) {
177176
)
178177
devToolsStore = store.liftedStore
179178

180-
history = syncHistoryWithStore(testHistory, store)
179+
history = syncHistoryWithStore(originalHistory, store)
181180
})
182181

183182
afterEach(() => {

test/browser/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'babel-polyfill'
22

3-
import { hashHistory, browserHistory } from 'react-router'
3+
import { createHashHistory, createHistory } from 'history'
44
import createTests from '../_createSyncTest'
55

6-
createTests(hashHistory, 'Hash History', () => window.location = '#/')
7-
createTests(browserHistory, 'Browser History', () => window.history.replaceState(null, null, '/'))
6+
createTests(createHashHistory, 'Hash History', () => window.location = '#/')
7+
createTests(createHistory, 'Browser History', () => window.history.replaceState(null, null, '/'))

test/sync.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createMemoryHistory } from 'react-router'
1+
import { createMemoryHistory } from 'history'
22
import createTests from './_createSyncTest'
33

4-
createTests(createMemoryHistory(), 'Memory History')
4+
createTests(createMemoryHistory, 'Memory History')

0 commit comments

Comments
 (0)