1
1
import axios from 'axios'
2
2
import MockAdapter from 'axios-mock-adapter'
3
3
4
+ import fakePostConfig from '@examples/apis-web/fake-post'
4
5
import { ERROR_STRINGS } from '@/constants'
5
6
import { fakeGetApi , fakePostApi } from '@examples/apis-web/'
6
7
@@ -19,6 +20,8 @@ const reqTAUrl = 'http://example-base.com/fake-get/req-type-axios?asyncCp=asyncC
19
20
const reqEAPUrl = 'http://example-base.com/fake-post/empty-array-params'
20
21
const reqMFDUrl = 'http://example-base.com/fake-get/mock-function-data'
21
22
const reqBFCUrl = 'http://example-base.com/fake-get/beforeFn-cookie'
23
+ const reqCTUrl = 'http://example-base.com/fake-post/custom-transformRequest'
24
+ const reqPjUrl = 'http://example-base.com/fake-post/post-json'
22
25
23
26
describe ( 'middleware' , ( ) => {
24
27
test ( 'change baseUrl before request' , async ( ) => {
@@ -164,4 +167,27 @@ describe('fake post requests', () => {
164
167
expect ( data ) . toBe ( formData )
165
168
expect ( transformRequest ) . toBe ( null )
166
169
} )
170
+
171
+ test ( 'custom-transformRequest' , async ( ) => {
172
+ mock . resetHistory ( )
173
+ mock . onPost ( reqCTUrl ) . reply ( 200 , { } )
174
+
175
+ await fakePostApi . ct ( )
176
+
177
+ const { data } = mock . history . post [ 0 ]
178
+
179
+ expect ( data ) . toBe ( 'ct' )
180
+ } )
181
+
182
+ test ( 'post-json' , async ( ) => {
183
+ mock . resetHistory ( )
184
+ mock . onPost ( reqPjUrl ) . reply ( 200 , { } )
185
+
186
+ await fakePostApi . pj ( )
187
+
188
+ const { data } = mock . history . post [ 0 ]
189
+
190
+ expect ( data ) . toBe ( JSON . stringify ( fakePostConfig . commonParams ) )
191
+ expect ( mock . history . post [ 0 ] . headers [ 'Content-Type' ] ) . toBe ( 'application/json;charset=utf-8' )
192
+ } )
167
193
} )
0 commit comments