global.URL
WHATWG URL without internationalized domain names; see docs/web-apis.md.
Usage
Handle requests in a screen test.
// Handle requests in a screen test.
import { Text, resource } from 'kuito';
import { assert, render, screen, test, type FetchHandler } from 'kuito/tests';
// A tiny fake server: answers by path, 404 for the rest.
const api: FetchHandler = (request) => {
const path = new URL(request.url).pathname;
if (path === '/me')
return { headers: { 'Content-Type': 'application/json' }, body: '{"name":"Ana"}' };
return { status: 404 };
};
function Greeting() {
const me = resource(async () => {
const response = await fetch('https://api.example.com/me');
return ((await response.json()) as { name: string }).name;
});
return <Text>{`Hi, ${me.data.value ?? '…'}`}</Text>;
}
test('greets the signed-in user', async () => {
await render(<Greeting />, { fetch: api });
assert.ok(screen.getByText('Hi, Ana'));
});Constructors
(url: string, base?: string | URL): URLParameters
| Name | Type | Required | Description |
|---|---|---|---|
url | string | Yes | — |
base | string | URL | No | — |
Returns
URL
Properties and methods 17
| Name | Type | Required | Description |
|---|---|---|---|
prototypereadonly | URL | Yes | — |
canParse | (url: string, base?: string) => boolean | Yes | — |
parse | (url: string, base?: string) => URL | null | Yes | — |
href | string | Yes | — |
originreadonly | string | Yes | — |
protocol | string | Yes | — |
username | string | Yes | — |
password | string | Yes | — |
host | string | Yes | — |
hostname | string | Yes | — |
port | string | Yes | — |
pathname | string | Yes | — |
search | string | Yes | — |
hash | string | Yes | — |
searchParamsreadonly | URLSearchParams | Yes | — |
toString | () => string | Yes | — |
toJSON | () => string | Yes | — |
canParse — method signatures
Signatures
(url: string, base?: string): booleanParameters
| Name | Type | Required | Description |
|---|---|---|---|
url | string | Yes | — |
base | string | No | — |
Returns
boolean
parse — method signatures
Signatures
(url: string, base?: string): URL | nullParameters
| Name | Type | Required | Description |
|---|---|---|---|
url | string | Yes | — |
base | string | No | — |
Returns
URL
toString — method signatures
Signatures
(): stringParameters
No parameters.
Returns
string
toJSON — method signatures
Signatures
(): stringParameters
No parameters.
Returns
string
Generated from the public TypeScript declarations: signatures, props and defaults come from the checked source, descriptions from its JSDoc. No defaults are invented.