File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -30,12 +30,11 @@ function fetchFactory<Paths>(options?: InitParameters) {
30
30
31
31
const fetchInit = buildInit ( defaultInit , options ) ;
32
32
const response = await fetchMethod ( url , fetchInit ) ;
33
-
34
- return {
35
- ...response ,
36
- ok : response . ok ,
33
+ return new Response ( response . body , {
37
34
status : response . status ,
38
- } as Omit < Response , "json" > & ResponseByStatus < Paths [ Path ] [ Method ] > ;
35
+ headers : response . headers ,
36
+ statusText : response . statusText ,
37
+ } ) as Omit < Response , "json" > & ResponseByStatus < Paths [ Path ] [ Method ] > ;
39
38
}
40
39
41
40
return fetcher ;
Original file line number Diff line number Diff line change @@ -2,9 +2,16 @@ import { FetchFactory } from "../../src/openapi-typescript";
2
2
import { paths , components } from "./test-data/petstore-openapi3" ;
3
3
import { IsEqual } from "../test-tools" ;
4
4
import { Immutable } from "../../src/types/utilities" ;
5
+ import { Readable } from "stream" ;
5
6
6
7
const mockedJson = jest . fn ( ( ) => ( { } as any ) ) ;
7
- const mockedFetch = jest . fn ( ( ) => ( { ok : true , json : mockedJson } as any ) ) ;
8
+ const mockedFetch = jest . fn (
9
+ ( ) =>
10
+ ( {
11
+ ok : true ,
12
+ body : Readable . from ( [ `{"hello": "world"}` ] ) ,
13
+ } as any )
14
+ ) ;
8
15
global . fetch = jest . fn ( ( ) => ( { ok : true , json : mockedJson } as any ) ) ;
9
16
10
17
const defaultFetch = FetchFactory . build < paths > ( ) ;
@@ -268,9 +275,9 @@ describe("Generated fetch request", () => {
268
275
describe ( "Generated fetch response" , ( ) => {
269
276
it ( "calls json() of response" , async ( ) => {
270
277
const response = await customFetch ( "/store/inventory" , { method : "get" } ) ;
271
- response . json ( ) ;
278
+ const payload = await response . json ( ) ;
272
279
273
- expect ( mockedJson . mock . calls ) . toHaveLength ( 1 ) ;
280
+ expect ( payload . hello ) . toBe ( "world" ) ;
274
281
} ) ;
275
282
276
283
it ( "can be discriminated based on ok property" , async ( ) => {
You can’t perform that action at this time.
0 commit comments