@@ -101,16 +101,34 @@ describe('submit', () => {
101
101
expect ( scope . isDone ( ) ) . toBe ( true ) ;
102
102
} ) ;
103
103
104
- it ( 'should accept and send request options' , async ( ) => {
104
+ describe ( 'requestInit option' , ( ) => {
105
105
const apiKey = 'foo-bar-baz' ;
106
106
const headers = { 'Api-Key' : apiKey } ;
107
- const scope = nock ( baseUrl , { reqheaders : headers } ) . get ( path ) . reply ( 204 ) ;
107
+ const action = new Action ( ) ;
108
+ action . name = 'foo' ;
109
+ action . href = url ;
110
+ action . method = 'POST' ;
111
+ action . fields = [ nameField ] ;
108
112
109
- const response = await submit ( action , { requestInit : { headers } } ) ;
113
+ it ( 'should send custom headers' , async ( ) => {
114
+ const scope = nock ( baseUrl , { reqheaders : headers } ) . post ( path ) . reply ( 204 ) ;
110
115
111
- expect ( response . url ) . toBe ( url ) ;
112
- expect ( response . status ) . toBe ( 204 ) ;
113
- expect ( scope . isDone ( ) ) . toBe ( true ) ;
116
+ const response = await submit ( action , { requestInit : { headers } } ) ;
117
+
118
+ expect ( response . url ) . toBe ( url ) ;
119
+ expect ( response . status ) . toBe ( 204 ) ;
120
+ expect ( scope . isDone ( ) ) . toBe ( true ) ;
121
+ } ) ;
122
+
123
+ it ( 'should merge custom headers with base headers' , async ( ) => {
124
+ const scope = nock ( baseUrl , { reqheaders : headers } ) . post ( path ) . reply ( 204 ) ;
125
+
126
+ const response = await submit ( action , { requestInit : { headers : Object . entries ( headers ) } } ) ;
127
+
128
+ expect ( response . url ) . toBe ( url ) ;
129
+ expect ( response . status ) . toBe ( 204 ) ;
130
+ expect ( scope . isDone ( ) ) . toBe ( true ) ;
131
+ } ) ;
114
132
} ) ;
115
133
116
134
it ( 'should resolve relative URL' , async ( ) => {
0 commit comments