@@ -10,14 +10,17 @@ const { ipcRenderer } = require('electron');
10
10
import { AppContext } from '../context/App' ;
11
11
import { LoginRoute } from './Login' ;
12
12
13
+ const mockNavigate = jest . fn ( ) ;
14
+ jest . mock ( 'react-router-dom' , ( ) => ( {
15
+ ...jest . requireActual ( 'react-router-dom' ) ,
16
+ useNavigate : ( ) => mockNavigate ,
17
+ } ) ) ;
18
+
13
19
describe ( 'routes/Login.tsx' , ( ) => {
14
20
const history = createMemoryHistory ( ) ;
15
- const pushMock = jest . spyOn ( history , 'push' ) ;
16
- const replaceMock = jest . spyOn ( history , 'replace' ) ;
17
-
18
- beforeEach ( function ( ) {
19
- pushMock . mockReset ( ) ;
20
21
22
+ beforeEach ( ( ) => {
23
+ mockNavigate . mockReset ( ) ;
21
24
jest . spyOn ( ipcRenderer , 'send' ) ;
22
25
} ) ;
23
26
@@ -34,35 +37,34 @@ describe('routes/Login.tsx', () => {
34
37
it ( 'should redirect to notifications once logged in' , ( ) => {
35
38
const { rerender } = render (
36
39
< AppContext . Provider value = { { isLoggedIn : false } } >
37
- < Router history = { history } >
40
+ < Router location = { history . location } navigator = { history } >
38
41
< LoginRoute />
39
42
</ Router >
40
43
</ AppContext . Provider > ,
41
44
) ;
42
45
43
46
rerender (
44
47
< AppContext . Provider value = { { isLoggedIn : true } } >
45
- < Router history = { history } >
48
+ < Router location = { history . location } navigator = { history } >
46
49
< LoginRoute />
47
50
</ Router >
48
51
</ AppContext . Provider > ,
49
52
) ;
50
53
51
54
expect ( ipcRenderer . send ) . toHaveBeenCalledTimes ( 1 ) ;
52
55
expect ( ipcRenderer . send ) . toHaveBeenCalledWith ( 'reopen-window' ) ;
53
- expect ( replaceMock ) . toHaveBeenCalledTimes ( 1 ) ;
56
+ expect ( mockNavigate ) . toHaveBeenNthCalledWith ( 1 , '/' , { replace : true } ) ;
54
57
} ) ;
55
58
56
59
it ( 'should navigate to login with github enterprise' , ( ) => {
57
60
const { getByLabelText } = render (
58
- < Router history = { history } >
61
+ < Router location = { history . location } navigator = { history } >
59
62
< LoginRoute />
60
63
</ Router > ,
61
64
) ;
62
65
63
66
fireEvent . click ( getByLabelText ( 'Login with GitHub Enterprise' ) ) ;
64
67
65
- expect ( pushMock ) . toHaveBeenCalledTimes ( 1 ) ;
66
- expect ( pushMock ) . toHaveBeenCalledWith ( '/login-enterprise' ) ;
68
+ expect ( mockNavigate ) . toHaveBeenNthCalledWith ( 1 , '/login-enterprise' ) ;
67
69
} ) ;
68
70
} ) ;
0 commit comments