@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
22import { makeClientWithInferredTypes } from "./api-client" ;
33import { Client } from "./api-client-types" ;
44import * as MockAPI from "../test-util/api-server" ;
5+ import { complicatedBasePath } from "../test-util/long-base-path-api" ;
56
67describe ( "API Client" , ( ) => {
78 describe ( "configuration options" , ( ) => {
@@ -31,6 +32,42 @@ describe("API Client", () => {
3132 } ) ;
3233 } ) ;
3334
35+ describe ( "long base paths" , ( ) => {
36+ let client : Client <
37+ MockAPI . APIWithCustomBasePathAPI ,
38+ MockAPI . APIWithCustomBasePathConfig
39+ > ;
40+ let mockFetch : typeof fetch ;
41+
42+ beforeEach ( ( ) => {
43+ mockFetch = vi . fn ( MockAPI . mockFetchImplementation ) ;
44+ const config = {
45+ fetch : mockFetch ,
46+ basePath : complicatedBasePath ,
47+ urlCase : "camel" ,
48+ } ;
49+ client = makeClientWithInferredTypes <
50+ MockAPI . APIWithCustomBasePathAPI ,
51+ MockAPI . APIWithCustomBasePathConfig
52+ > ( config ) ;
53+ } ) ;
54+
55+ afterEach ( ( ) => {
56+ vi . restoreAllMocks ( ) ;
57+ } ) ;
58+
59+ it ( "preserves base path, including casing" , async ( ) => {
60+ const dogs = await client . dogs . list ( ) ;
61+ expect ( mockFetch ) . toHaveBeenCalledWith (
62+ "/api/camelCase/kebab-case/v2/dogs" ,
63+ {
64+ method : "GET" ,
65+ }
66+ ) ;
67+ expect ( dogs ) . toStrictEqual ( [ { name : "Fido" , color : "red" } ] ) ;
68+ } ) ;
69+ } ) ;
70+
3471 describe ( "fetch calls" , ( ) => {
3572 let client : Client < MockAPI . API , MockAPI . Config > ;
3673 let mockFetch : typeof fetch ;
0 commit comments