-
Notifications
You must be signed in to change notification settings - Fork 961
/
describeHashSupport.js
70 lines (61 loc) · 2.04 KB
/
describeHashSupport.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
import expect from 'expect'
import { PUSH, POP } from '../Actions'
import execSteps from './execSteps'
function describeHashSupport(createHistory) {
describe('when a URL with a hash is pushed', function () {
let history, unlisten
beforeEach(function () {
history = createHistory()
})
afterEach(function () {
if (unlisten)
unlisten()
})
it('preserves the hash', function (done) {
const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
expect(location.hash).toEqual('')
expect(location.state).toEqual(null)
expect(location.action).toEqual(POP)
history.push({
pathname: '/home',
search: '?the=query',
hash: '#the-hash',
state: { the: 'state' }
})
},
function (location) {
expect(location.pathname).toEqual('/home')
expect(location.search).toEqual('?the=query')
expect(location.hash).toEqual('#the-hash')
expect(location.state).toEqual({ the: 'state' })
expect(location.action).toEqual(PUSH)
}
]
unlisten = history.listen(execSteps(steps, done))
})
it('does not convert PUSH to REPLACE if path does not change', function (done) {
const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
expect(location.hash).toEqual('')
expect(location.state).toEqual(null)
expect(location.action).toEqual(POP)
history.push('/#the-hash')
},
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
expect(location.hash).toEqual('#the-hash')
expect(location.state).toEqual(null)
expect(location.action).toEqual(PUSH)
}
]
unlisten = history.listen(execSteps(steps, done))
})
})
}
export default describeHashSupport