global.URL
WHATWG URL without internationalized domain names; see docs/web-apis.md.
Utilização
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'));
});Construtores
(url: string, base?: string | URL): URLParâmetros
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
url | string | Sim | — |
base | string | URL | Não | — |
Devolve
URL
Propriedades e métodos 17
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
prototypesó de leitura | URL | Sim | — |
canParse | (url: string, base?: string) => boolean | Sim | — |
parse | (url: string, base?: string) => URL | null | Sim | — |
href | string | Sim | — |
originsó de leitura | string | Sim | — |
protocol | string | Sim | — |
username | string | Sim | — |
password | string | Sim | — |
host | string | Sim | — |
hostname | string | Sim | — |
port | string | Sim | — |
pathname | string | Sim | — |
search | string | Sim | — |
hash | string | Sim | — |
searchParamssó de leitura | URLSearchParams | Sim | — |
toString | () => string | Sim | — |
toJSON | () => string | Sim | — |
canParse — assinaturas de método
Assinaturas
(url: string, base?: string): booleanParâmetros
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
url | string | Sim | — |
base | string | Não | — |
Devolve
boolean
parse — assinaturas de método
Assinaturas
(url: string, base?: string): URL | nullParâmetros
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
url | string | Sim | — |
base | string | Não | — |
Devolve
URL
toString — assinaturas de método
Assinaturas
(): stringParâmetros
Sem parâmetros.
Devolve
string
toJSON — assinaturas de método
Assinaturas
(): stringParâmetros
Sem parâmetros.
Devolve
string
Gerado a partir das declarações TypeScript públicas: assinaturas, props e predefinições vêm da fonte verificada, as descrições da sua JSDoc. Nenhuma predefinição é inventada.