1
1
import { AxiosPromise , AxiosResponse } from 'axios' ;
2
2
3
- const { remote } = require ( 'electron' ) ;
4
- const BrowserWindow = remote . BrowserWindow ;
3
+ import { remote } from 'electron' ;
4
+ const browserWindow = new remote . BrowserWindow
5
5
6
6
import * as auth from './auth' ;
7
7
import * as apiRequests from './api-requests' ;
8
8
import { AuthState } from '../types' ;
9
9
10
10
describe ( 'utils/auth.tsx' , ( ) => {
11
11
describe ( 'authGitHub' , ( ) => {
12
- const loadURLMock = jest . spyOn ( new BrowserWindow ( ) , 'loadURL' ) ;
12
+ const loadURLMock = jest . spyOn ( browserWindow , 'loadURL' ) ;
13
13
14
14
beforeEach ( ( ) => {
15
15
loadURLMock . mockReset ( ) ;
16
16
} ) ;
17
17
18
18
it ( 'should call authGithub - success' , async ( ) => {
19
- spyOn ( new BrowserWindow ( ) . webContents , 'on' ) . and . callFake (
19
+ spyOn ( browserWindow . webContents , 'on' ) . and . callFake (
20
20
( event , callback ) => {
21
21
if ( event === 'will-redirect' ) {
22
22
const event = new Event ( 'will-redirect' ) ;
@@ -30,19 +30,19 @@ describe('utils/auth.tsx', () => {
30
30
expect ( res . authCode ) . toBe ( '123-456' ) ;
31
31
32
32
expect (
33
- new BrowserWindow ( ) . webContents . session . clearStorageData
33
+ browserWindow . webContents . session . clearStorageData
34
34
) . toHaveBeenCalledTimes ( 1 ) ;
35
35
36
36
expect ( loadURLMock ) . toHaveBeenCalledTimes ( 1 ) ;
37
37
expect ( loadURLMock ) . toHaveBeenCalledWith (
38
- 'https://github.com/login/oauth/authorize?client_id=FAKE_CLIENT_ID_123&scope=read:user,notifications'
38
+ 'https://github.com/login/oauth/authorize?client_id=FAKE_CLIENT_ID_123&scope=read:user,notifications,repo '
39
39
) ;
40
40
41
- expect ( new BrowserWindow ( ) . destroy ) . toHaveBeenCalledTimes ( 1 ) ;
41
+ expect ( browserWindow . destroy ) . toHaveBeenCalledTimes ( 1 ) ;
42
42
} ) ;
43
43
44
44
it ( 'should call authGithub - failure' , async ( ) => {
45
- spyOn ( new BrowserWindow ( ) . webContents , 'on' ) . and . callFake (
45
+ spyOn ( browserWindow . webContents , 'on' ) . and . callFake (
46
46
( event , callback ) => {
47
47
if ( event === 'will-redirect' ) {
48
48
const event = new Event ( 'will-redirect' ) ;
0 commit comments