-
Notifications
You must be signed in to change notification settings - Fork 961
/
MemoryHistory-test.js
87 lines (71 loc) · 2.33 KB
/
MemoryHistory-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import expect from 'expect'
import createMemoryHistory from '../createMemoryHistory'
import describeInitialLocation from './describeInitialLocation'
import describeTransitions from './describeTransitions'
import describePushState from './describePushState'
import describePush from './describePush'
import describeReplaceState from './describeReplaceState'
import describeReplace from './describeReplace'
import describeBasename from './describeBasename'
import describeQueries from './describeQueries'
import describeGo from './describeGo'
describe('memory history', function () {
describeInitialLocation(createMemoryHistory)
describeTransitions(createMemoryHistory)
describePushState(createMemoryHistory)
describePush(createMemoryHistory)
describeReplaceState(createMemoryHistory)
describeReplace(createMemoryHistory)
describeBasename(createMemoryHistory)
describeQueries(createMemoryHistory)
describeGo(createMemoryHistory)
describe('when using push in the middle of the stack', function () {
it('clears rest of stack so the user cannot go forward', function () {
let history = createMemoryHistory(), location
history.listen(function (loc) {
location = loc
})
history.push({
pathname: '/1',
state: { id: 1 }
})
history.push({
pathname: '/2',
state: { id: 2 }
})
history.push({
pathname: '/3',
state: { id: 3 }
})
history.push({
pathname: '/4',
state: { id: 4 }
})
expect(location.state).toEqual({ id: 4 })
history.go(-2)
expect(location.state).toEqual({ id: 2 })
history.push({
pathname: '/5',
state: { id: 5 }
})
expect(location.state).toEqual({ id: 5 })
expect(location.pathname).toEqual('/5')
history.goBack()
expect(location.state).toEqual({ id: 2 })
history.goForward()
expect(location.state).toEqual({ id: 5 })
expect(location.pathname).toEqual('/5')
expect(function () {
history.goForward()
}).toThrow(/Cannot go\(\d+\) there is not enough history/)
history.goBack()
history.push({
pathname: '/6',
state: { id: 6 }
})
expect(function () {
history.goForward()
}).toThrow(/Cannot go\(\d+\) there is not enough history/)
})
})
})