@@ -170,18 +170,32 @@ describe('FSXAApi', () => {
170
170
171
171
describe ( 'fetchPage' , async ( ) => {
172
172
it ( 'should call local url in proxy-mode' , async ( ) => {
173
- testForLocalUrl ( api => api . fetchElement ( 'foobar' , 'de_DE' ) )
173
+ await testForLocalUrl ( api => api . fetchElement ( 'foobar' , 'de_DE' ) )
174
174
} )
175
175
} )
176
176
177
177
describe ( 'fetchNavigation' , async ( ) => {
178
178
it ( 'should call local url in proxy-mode' , async ( ) => {
179
- testForLocalUrl ( api => api . fetchNavigation ( null , 'de_DE' ) )
179
+ await testForLocalUrl ( api => api . fetchNavigation ( null , 'de_DE' ) )
180
+ } )
181
+
182
+ it ( 'should pass extraHeaders' , async ( ) => {
183
+ await testForLocalUrl (
184
+ api => api . fetchNavigation ( null , 'de_DE' , { 'x-test' : 'foobar' } ) ,
185
+ fetch => {
186
+ const request = fetch . mock . calls [ 0 ] [ 1 ]
187
+ const headers = request && request [ 'headers' ]
188
+ expect ( headers && 'x-test' in headers && headers [ 'x-test' ] ) . toBe ( 'foobar' )
189
+ }
190
+ )
180
191
} )
181
192
} )
182
193
} )
183
194
184
- const testForLocalUrl = async ( method : ( api : FSXAApi ) => Promise < any > ) => {
195
+ const testForLocalUrl = async (
196
+ method : ( api : FSXAApi ) => Promise < any > ,
197
+ validate ?: ( fetch : FetchMock ) => void
198
+ ) => {
185
199
fetchMock . enableMocks ( )
186
200
const api = new FSXAApi ( FSXAContentMode . PREVIEW , {
187
201
mode : 'proxy' ,
@@ -193,5 +207,6 @@ const testForLocalUrl = async (method: (api: FSXAApi) => Promise<any>) => {
193
207
await method ( api )
194
208
expect ( mockedFetch ) . toHaveBeenCalledTimes ( 1 )
195
209
expect ( mockedFetch . mock . calls [ 0 ] [ 0 ] ) . toMatch ( / l o c a l h o s t / g)
210
+ validate && validate ( fetchMock )
196
211
fetchMock . disableMocks ( )
197
212
}
0 commit comments