@@ -8,8 +8,8 @@ import Redirect from '../Redirect'
8
8
import Router from '../Router'
9
9
import Route from '../Route'
10
10
11
- describe ( 'useRouterHistory' , function ( ) {
12
- it ( 'passes along options, especially query parsing' , function ( done ) {
11
+ describe ( 'useRouterHistory' , ( ) => {
12
+ it ( 'passes along options, especially query parsing' , done => {
13
13
const history = useRouterHistory ( createHistory ) ( {
14
14
stringifyQuery ( ) {
15
15
assert ( true )
@@ -20,40 +20,46 @@ describe('useRouterHistory', function () {
20
20
history . push ( { pathname : '/' , query : { test : true } } )
21
21
} )
22
22
23
- describe ( 'when using basename' , function ( ) {
23
+ describe ( 'when using basename' , ( ) => {
24
24
25
25
let node
26
- beforeEach ( function ( ) {
26
+ beforeEach ( ( ) => {
27
27
node = document . createElement ( 'div' )
28
28
} )
29
29
30
- afterEach ( function ( ) {
30
+ afterEach ( ( ) => {
31
31
unmountComponentAtNode ( node )
32
32
} )
33
33
34
- it ( 'should regard basename' , function ( done ) {
35
- const pathnames = [ ]
36
- const basenames = [ ]
34
+ it ( 'should regard basename' , ( ) => {
37
35
const history = useRouterHistory ( createHistory ) ( {
38
36
entries : '/foo/notes/5' ,
39
37
basename : '/foo'
40
38
} )
41
- history . listen ( function ( location ) {
39
+
40
+ const pathnames = [ ]
41
+ const basenames = [ ]
42
+
43
+ const currentLocation = history . getCurrentLocation ( )
44
+ pathnames . push ( currentLocation . pathname )
45
+ basenames . push ( currentLocation . basename )
46
+
47
+ history . listen ( location => {
42
48
pathnames . push ( location . pathname )
43
49
basenames . push ( location . basename )
44
50
} )
45
- render ( (
51
+
52
+ const instance = render ( (
46
53
< Router history = { history } >
47
54
< Route path = "/messages/:id" />
48
55
< Redirect from = "/notes/:id" to = "/messages/:id" />
49
56
</ Router >
50
- ) , node , function ( ) {
51
- expect ( pathnames ) . toEqual ( [ '/notes/5' , '/messages/5' ] )
52
- expect ( basenames ) . toEqual ( [ '/foo' , '/foo' ] )
53
- expect ( this . state . location . pathname ) . toEqual ( '/messages/5' )
54
- expect ( this . state . location . basename ) . toEqual ( '/foo' )
55
- done ( )
56
- } )
57
+ ) , node )
58
+
59
+ expect ( pathnames ) . toEqual ( [ '/notes/5' , '/messages/5' ] )
60
+ expect ( basenames ) . toEqual ( [ '/foo' , '/foo' ] )
61
+ expect ( instance . state . location . pathname ) . toEqual ( '/messages/5' )
62
+ expect ( instance . state . location . basename ) . toEqual ( '/foo' )
57
63
} )
58
64
} )
59
65
} )
0 commit comments