use-query-params
Version:
React Hook for managing state in URL query parameters with easy serialization.
27 lines (25 loc) • 997 B
text/typescript
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect';
import { fetch, Request, Response } from '@remix-run/web-fetch';
// https://stackoverflow.com/a/74501698/14056107
// prevent Request not being defined in Vitest
if (!globalThis.fetch) {
// Built-in lib.dom.d.ts expects `fetch(Request | string, ...)` but the web
// fetch API allows a URL so @remix-run/web-fetch defines
// `fetch(string | URL | Request, ...)`
// @ts-expect-error
globalThis.fetch = fetch;
}
if (!globalThis.Request) {
// Same as above, lib.dom.d.ts doesn't allow a URL to the Request constructor
// @ts-expect-error
globalThis.Request = Request;
}
if (!globalThis.Response) {
// web-std/fetch Response does not currently implement Response.error()
// @ts-expect-error
globalThis.Response = Response;
}