@@ -14,6 +14,9 @@ import {
14
14
smallBranchStyle
15
15
} from '../../src/componentsStyle/BranchHeaderStyle' ;
16
16
17
+ // Mock jupyterlab package
18
+ jest . mock ( '@jupyterlab/apputils' ) ;
19
+
17
20
describe ( 'BranchHeader' , ( ) => {
18
21
let props : IBranchHeaderProps = {
19
22
currentFileBrowserPath : '/current/absolute/path' ,
@@ -55,17 +58,16 @@ describe('BranchHeader', () => {
55
58
it ( 'should commit when commit message is provided' , async ( ) => {
56
59
const spy = jest . spyOn ( Git . prototype , 'commit' ) ;
57
60
// Mock identity look up
58
- const identity = jest . spyOn ( Git . prototype , 'config' ) . mockImplementation (
59
- ( ) =>
60
- new Response (
61
- JSON . stringify ( {
62
- options : {
63
- 'user.name' : 'John Snow' ,
64
-
65
- }
66
- } ) ,
67
- { status : 201 }
68
- )
61
+ const identity = jest . spyOn ( Git . prototype , 'config' ) . mockResolvedValue (
62
+ new Response (
63
+ JSON . stringify ( {
64
+ options : {
65
+ 'user.name' : 'John Snow' ,
66
+
67
+ }
68
+ } ) ,
69
+ { status : 201 }
70
+ )
69
71
) ;
70
72
await branchHeader . commitAllStagedFiles (
71
73
'Initial commit' ,
@@ -93,8 +95,9 @@ describe('BranchHeader', () => {
93
95
const identity = jest
94
96
. spyOn ( Git . prototype , 'config' )
95
97
. mockImplementation ( ( path , options ) => {
98
+ let response : Response = null ;
96
99
if ( options === undefined ) {
97
- return new Response (
100
+ response = new Response (
98
101
JSON . stringify ( {
99
102
options : {
100
103
@@ -103,20 +106,26 @@ describe('BranchHeader', () => {
103
106
{ status : 201 }
104
107
) ;
105
108
} else {
106
- return new Response ( '' , { status : 201 } ) ;
109
+ response = new Response ( '' , { status : 201 } ) ;
107
110
}
111
+ return Promise . resolve ( response ) ;
108
112
} ) ;
109
- jest . spyOn ( apputils , 'showDialog' ) . mockReturnValue (
110
- Promise . resolve ( {
111
- button : {
112
- accept : true
113
- } ,
114
- value : {
115
- name : 'John Snow' ,
116
-
117
- }
118
- } )
119
- ) ;
113
+ const mockApputils = apputils as jest . Mocked < typeof apputils > ;
114
+ mockApputils . showDialog . mockResolvedValue ( {
115
+ button : {
116
+ accept : true ,
117
+ caption : '' ,
118
+ className : '' ,
119
+ displayType : 'default' ,
120
+ iconClass : '' ,
121
+ iconLabel : '' ,
122
+ label : ''
123
+ } ,
124
+ value : {
125
+ name : 'John Snow' ,
126
+
127
+ }
128
+ } ) ;
120
129
121
130
await branchHeader . commitAllStagedFiles (
122
131
'Initial commit' ,
@@ -145,8 +154,9 @@ describe('BranchHeader', () => {
145
154
const identity = jest
146
155
. spyOn ( Git . prototype , 'config' )
147
156
. mockImplementation ( ( path , options ) => {
157
+ let response : Response = null ;
148
158
if ( options === undefined ) {
149
- return new Response (
159
+ response = new Response (
150
160
JSON . stringify ( {
151
161
options : {
152
162
'user.name' : 'John Snow'
@@ -155,12 +165,20 @@ describe('BranchHeader', () => {
155
165
{ status : 201 }
156
166
) ;
157
167
} else {
158
- return new Response ( '' , { status : 201 } ) ;
168
+ response = new Response ( '' , { status : 201 } ) ;
159
169
}
170
+ return Promise . resolve ( response ) ;
160
171
} ) ;
161
- jest . spyOn ( apputils , 'showDialog' ) . mockReturnValue ( {
172
+ const mockApputils = apputils as jest . Mocked < typeof apputils > ;
173
+ mockApputils . showDialog . mockResolvedValue ( {
162
174
button : {
163
- accept : true
175
+ accept : true ,
176
+ caption : '' ,
177
+ className : '' ,
178
+ displayType : 'default' ,
179
+ iconClass : '' ,
180
+ iconLabel : '' ,
181
+ label : ''
164
182
} ,
165
183
value : {
166
184
name : 'John Snow' ,
@@ -195,21 +213,31 @@ describe('BranchHeader', () => {
195
213
const identity = jest
196
214
. spyOn ( Git . prototype , 'config' )
197
215
. mockImplementation ( ( path , options ) => {
216
+ let response : Response = null ;
198
217
if ( options === undefined ) {
199
- return new Response (
218
+ response = new Response (
200
219
JSON . stringify ( {
201
220
options : { }
202
221
} ) ,
203
222
{ status : 201 }
204
223
) ;
205
224
} else {
206
- return new Response ( '' , { status : 201 } ) ;
225
+ response = new Response ( '' , { status : 201 } ) ;
207
226
}
227
+ return Promise . resolve ( response ) ;
208
228
} ) ;
209
- jest . spyOn ( apputils , 'showDialog' ) . mockReturnValue ( {
229
+ const mockApputils = apputils as jest . Mocked < typeof apputils > ;
230
+ mockApputils . showDialog . mockResolvedValue ( {
210
231
button : {
211
- accept : false
212
- }
232
+ accept : false ,
233
+ caption : '' ,
234
+ className : '' ,
235
+ displayType : 'default' ,
236
+ iconClass : '' ,
237
+ iconLabel : '' ,
238
+ label : ''
239
+ } ,
240
+ value : null
213
241
} ) ;
214
242
215
243
await branchHeader . commitAllStagedFiles (
0 commit comments