diff --git a/package.json b/package.json index a551131..13c8b4d 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ }, "devDependencies": { "@nuxt/h2": "^0.0.14", - "@nuxt/ufo": "^0.1.3", + "@nuxt/ufo": "^0.1.4", "@nuxtjs/eslint-config-typescript": "latest", "@types/flat": "latest", "@types/jest": "latest", diff --git a/test/index.test.ts b/test/index.test.ts index a4b1174..0fd3c4e 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -7,7 +7,10 @@ describe('ohmyfetch', () => { let listener: Listener it('setup', async () => { - const app = createApp().use('/api', req => (getParams(req.url || ''))) + const app = createApp() + .use('/ok', () => 'ok') + .use('/params', req => (getParams(req.url || ''))) + .use('/url', req => req.url) listener = await listen(app) }) @@ -15,18 +18,19 @@ describe('ohmyfetch', () => { await listener.close() }) - it('api', async () => { - expect(await $fetch('api', { - baseURL: listener.url, - params: { api: 1 } - })).toMatchObject({ api: '1' }) + it('ok', async () => { + expect(await $fetch(listener.getURL('ok'))).toBe('ok') + }) + + it('baseURL', async () => { + expect(await $fetch('/x?foo=123', { baseURL: listener.getURL('url') })).toBe('/x?foo=123') }) it('404', async () => { - const err: FetchError = await $fetch('404', { baseURL: listener.url }).catch(err => err) + const err: FetchError = await $fetch(listener.getURL('404'), { baseURL: listener.url }).catch(err => err) expect(err.stack).toMatch('404 Not Found') expect(err.data).toMatch('Not Found (404)') expect(err.response?.data).toBe(err.data) - expect(err.request).toBe('http://localhost:3000/404') + expect(err.request).toBe(listener.getURL('404')) }) }) diff --git a/yarn.lock b/yarn.lock index 7120dbf..46f026a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -513,10 +513,10 @@ resolved "https://registry.yarnpkg.com/@nuxt/ufo/-/ufo-0.0.3.tgz#7673a54b81c020e7aea3a9e01e09a58c494a1eca" integrity sha512-LQkuVafVNB9+ggRF7443AX1V1rEWRs32Frk7F2qnRLf8j/SzRzxEZ99jiZqxVho72zU7NcWQ6Jy62m4fkZC6Wg== -"@nuxt/ufo@^0.1.3": - version "0.1.3" - resolved "https://registry.yarnpkg.com/@nuxt/ufo/-/ufo-0.1.3.tgz#bd6403623f441de599f52cf5bdf4ccc99476e0b9" - integrity sha512-z62gwk1m0SX7N+GWkJo8VLQiIieT0NRttz2giExUhel1iL3b773653YvFGhfTURCdOmU5rlCPsQmVgZjH5XqAg== +"@nuxt/ufo@^0.1.4": + version "0.1.4" + resolved "https://registry.yarnpkg.com/@nuxt/ufo/-/ufo-0.1.4.tgz#41967f00333821c8760f8ee71c50e37c534b7ac6" + integrity sha512-uEfXbPROYZcRbnkVS2NK2vklDpcfZOAjGaniuC4pKJAgHTx0A4f8uMC1R5BSTA8zNZAoweDc7pW6tqvu/JyIhQ== "@nuxtjs/eslint-config-typescript@latest": version "5.0.0"