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

Commit 4308208

Browse files
committed
Add back some other relevant tests.
1 parent 50faa62 commit 4308208

File tree

1 file changed

+86
-4
lines changed

1 file changed

+86
-4
lines changed

test/_createSyncTest.js

+86-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import expect from 'expect'
22

33
import { createStore, combineReducers } from 'redux'
4-
// import { ActionCreators, instrument } from 'redux-devtools'
5-
// import { useBasename, useQueries } from 'history'
4+
import { ActionCreators, instrument } from 'redux-devtools'
65

76
import syncHistoryWithStore from '../src/sync'
87
import { routerReducer } from '../src/reducer'
9-
// import routerMiddleware from '../src/middleware'
108

119
expect.extend({
1210
toContainLocation({
@@ -42,7 +40,7 @@ function createSyncedHistoryAndStore(testHistory) {
4240

4341
const defaultReset = () => {}
4442

45-
module.exports = function createTests(testHistory, name, reset = defaultReset) {
43+
export default function createTests(testHistory, name, reset = defaultReset) {
4644
describe(name, () => {
4745

4846
beforeEach(reset)
@@ -131,7 +129,91 @@ module.exports = function createTests(testHistory, name, reset = defaultReset) {
131129
action: 'REPLACE'
132130
})
133131
})
132+
133+
it('provices an unsubscribe method to stop listening to history and store', () => {
134+
history.push('/foo')
135+
expect(store).toContainLocation({
136+
pathname: '/foo'
137+
})
138+
139+
history.unsubscribe()
140+
141+
history.push('/bar')
142+
expect(store).toContainLocation({
143+
pathname: '/foo'
144+
})
145+
})
146+
147+
it('updates the router even if path is the same', () => {
148+
history.push('/')
149+
150+
const updates = []
151+
const historyUnsubscribe = history.listen(location => {
152+
updates.push(location.pathname)
153+
})
154+
155+
history.push('/foo')
156+
history.push('/foo')
157+
history.replace('/foo')
158+
159+
expect(updates).toEqual([ '/', '/foo', '/foo', '/foo' ])
160+
161+
historyUnsubscribe()
162+
})
134163
})
135164

165+
describe('Redux DevTools', () => {
166+
let history, store, devToolsStore
167+
168+
beforeEach(() => {
169+
// Set initial URL before syncing
170+
testHistory.push('/foo')
171+
172+
store = createStore(
173+
combineReducers({
174+
routing: routerReducer
175+
}),
176+
instrument()
177+
)
178+
devToolsStore = store.liftedStore
179+
180+
history = syncHistoryWithStore(testHistory, store)
181+
})
182+
183+
afterEach(() => {
184+
history.unsubscribe()
185+
})
186+
187+
it('resets to the initial url', () => {
188+
let currentPath
189+
const historyUnsubscribe = history.listen(location => {
190+
currentPath = location.pathname
191+
})
192+
193+
history.push('/bar')
194+
devToolsStore.dispatch(ActionCreators.reset())
195+
196+
expect(currentPath).toEqual('/foo')
197+
198+
historyUnsubscribe()
199+
})
200+
201+
it('handles toggle after history change', () => {
202+
let currentPath
203+
const historyUnsubscribe = history.listen(location => {
204+
currentPath = location.pathname
205+
})
206+
207+
history.push('/foo2') // DevTools action #2
208+
history.push('/foo3') // DevTools action #3
209+
210+
// When we toggle an action, the devtools will revert the action
211+
// and we therefore expect the history to update to the previous path
212+
devToolsStore.dispatch(ActionCreators.toggleAction(3))
213+
expect(currentPath).toEqual('/foo2')
214+
215+
historyUnsubscribe()
216+
})
217+
})
136218
})
137219
}

0 commit comments

Comments
 (0)