Skip to content

[feat]: parseAs options reports correct data type #1428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 6, 2023
17 changes: 9 additions & 8 deletions packages/openapi-fetch/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,9 @@ describe("client", () => {
it("text", async () => {
const client = createClient<paths>();
mockFetchOnce({ status: 200, body: "{}" });
const { data, error } = await client.GET("/anyMethod", {
const { data, error } = (await client.GET("/anyMethod", {
parseAs: "text",
});
})) satisfies { data?: string };
if (error) {
throw new Error(`parseAs text: error`);
}
Expand All @@ -581,9 +581,9 @@ describe("client", () => {
it("arrayBuffer", async () => {
const client = createClient<paths>();
mockFetchOnce({ status: 200, body: "{}" });
const { data, error } = await client.GET("/anyMethod", {
const { data, error } = (await client.GET("/anyMethod", {
parseAs: "arrayBuffer",
});
})) satisfies { data?: ArrayBuffer };
if (error) {
throw new Error(`parseAs arrayBuffer: error`);
}
Expand All @@ -593,9 +593,9 @@ describe("client", () => {
it("blob", async () => {
const client = createClient<paths>();
mockFetchOnce({ status: 200, body: "{}" });
const { data, error } = await client.GET("/anyMethod", {
const { data, error } = (await client.GET("/anyMethod", {
parseAs: "blob",
});
})) satisfies { data?: Blob };
if (error) {
throw new Error(`parseAs blob: error`);
}
Expand All @@ -605,12 +605,13 @@ describe("client", () => {
it("stream", async () => {
const client = createClient<paths>();
mockFetchOnce({ status: 200, body: "{}" });
const { data } = await client.GET("/anyMethod", {
const { data } = (await client.GET("/anyMethod", {
parseAs: "stream",
});
})) satisfies { data?: ReadableStream<Uint8Array> | null };
if (!data) {
throw new Error(`parseAs stream: error`);
}
// todo - not sure what test to put here - previously it just checked for instanceof Buffer
expect(data.byteLength).toBe(8);
});
});
Expand Down