File tree 2 files changed +26
-2
lines changed
2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -13,10 +13,11 @@ class RPCClient {
13
13
call ( name , args , headers = { } ) {
14
14
return fetch ( `${ this . url } /${ name } ` , {
15
15
method : 'POST' ,
16
- headers : Object . assign ( {
16
+ headers : {
17
17
Accept : 'application/json' ,
18
18
'Content-Type' : 'application/json' ,
19
- } , headers ) ,
19
+ ...headers ,
20
+ } ,
20
21
body : JSON . stringify ( {
21
22
args : JSON . stringify ( args ) ,
22
23
} ) ,
Original file line number Diff line number Diff line change @@ -123,4 +123,27 @@ describe('RPCClient', () => {
123
123
}
124
124
} ) ;
125
125
} ) ;
126
+
127
+ describe ( 'headers' , ( ) => {
128
+ it ( 'should call RPC method with headers' , async ( ) => {
129
+ const name = 'someMethod' ;
130
+ const args = { a : 'a' , b : 'b' } ;
131
+ const headers = { foo : 'bar' } ;
132
+ const rpc = new RPCClient ( ) ;
133
+ const response = await rpc . call ( name , args , headers ) ;
134
+
135
+ expect ( fetch ) . toBeCalledWith ( 'http://localhost/someMethod' , {
136
+ method : 'POST' ,
137
+ headers : {
138
+ Accept : 'application/json' ,
139
+ 'Content-Type' : 'application/json' ,
140
+ ...headers ,
141
+ } ,
142
+ body : JSON . stringify ( {
143
+ args : JSON . stringify ( args ) ,
144
+ } ) ,
145
+ } ) ;
146
+ expect ( response ) . toEqual ( fetch . fakeResponse ) ;
147
+ } ) ;
148
+ } ) ;
126
149
} ) ;
You can’t perform that action at this time.
0 commit comments