{"id":51914259,"url":"https://github.com/loke-dev/expect-fetch","last_synced_at":"2026-07-27T09:01:49.873Z","repository":{"id":373270516,"uuid":"1312890929","full_name":"loke-dev/expect-fetch","owner":"loke-dev","description":"Expressive Vitest matchers for native Fetch API responses","archived":false,"fork":false,"pushed_at":"2026-07-26T18:24:16.000Z","size":80,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-07-26T19:11:32.923Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loke-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-07-26T14:54:04.000Z","updated_at":"2026-07-26T18:24:26.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/loke-dev/expect-fetch","commit_stats":null,"previous_names":["loke-dev/expect-fetch"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/loke-dev/expect-fetch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loke-dev%2Fexpect-fetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loke-dev%2Fexpect-fetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loke-dev%2Fexpect-fetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loke-dev%2Fexpect-fetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loke-dev","download_url":"https://codeload.github.com/loke-dev/expect-fetch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loke-dev%2Fexpect-fetch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35945273,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-07-20T02:08:10.276Z","status":"online","status_checked_at":"2026-07-27T02:00:06.776Z","response_time":101,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-07-27T09:01:49.133Z","updated_at":"2026-07-27T09:01:49.866Z","avatar_url":"https://github.com/loke-dev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# expect-fetch\n\nJest DOM-style assertions for native Fetch API requests and responses.\n\n`expect-fetch` adds expressive HTTP matchers to Vitest without mocking\n`globalThis.fetch`. Use it to test Next.js route handlers, Remix loaders,\nSvelteKit and Astro endpoints, Hono applications, Cloudflare Workers, or any\ncode that produces native `Request` or `Response` objects.\n\n```ts\nimport 'expect-fetch/vitest';\n\nconst response = await app.request('/users/123');\n\nexpect(response).toHaveStatus(200);\nexpect(response).toHaveHeader('content-type', /json/);\n\nawait expect(response).toHaveJson({\n  id: '123',\n  name: 'Ada',\n});\n```\n\nRequest assertions use the same API:\n\n```ts\nexpect(request).toHaveMethod('POST');\nexpect(request).toHaveUrl('/users?page=2');\nexpect(request).toHaveQuery({ page: '2' });\nexpect(request).toHaveHeader('authorization', /^Bearer /);\n\nawait expect(request).toHaveJson({ name: 'Ada' });\n```\n\n## Installation\n\n```sh\nnpm install --save-dev expect-fetch\n```\n\nAdd the integration to a Vitest setup file:\n\n```ts\n// test/setup.ts\nimport 'expect-fetch/vitest';\n```\n\n```ts\n// vitest.config.ts\nimport { defineConfig } from 'vitest/config';\n\nexport default defineConfig({\n  test: {\n    setupFiles: ['./test/setup.ts'],\n  },\n});\n```\n\nYou can also import the integration directly in an individual test file.\n\n## Matchers\n\n### `toHaveStatus`\n\n```ts\nexpect(response).toHaveStatus(201);\n```\n\n### `toHaveHeader`\n\nHeader names are case-insensitive. Values can be exact strings or regular\nexpressions. Requests and responses are supported.\n\n```ts\nexpect(response).toHaveHeader('content-type');\nexpect(response).toHaveHeader('content-type', /application\\/json/);\nexpect(response).toHaveHeader('x-request-id', 'req_123');\n```\n\n### `toHaveJson`\n\nThe request or response is cloned before its body is read, so the matcher does\nnot consume the original body. Vitest asymmetric matchers are supported.\n\n```ts\nawait expect(response).toHaveJson({\n  id: expect.any(String),\n  role: 'admin',\n});\n```\n\n### `toHaveText`\n\n```ts\nawait expect(response).toHaveText('Not found');\nawait expect(response).toHaveText(/not found/i);\n```\n\n### `toHaveFormData`\n\nRepeated fields are represented as arrays. Requests and responses are\nsupported.\n\n```ts\nawait expect(request).toHaveFormData({\n  name: 'Ada',\n  roles: ['admin', 'author'],\n  avatar: expect.any(File),\n});\n```\n\n### `toHaveMethod`\n\nMethod comparison is case-insensitive.\n\n```ts\nexpect(request).toHaveMethod('POST');\n```\n\n### `toHaveUrl`\n\nAbsolute URLs, `URL` objects, regular expressions, and relative URLs containing\nthe path, query, and fragment are supported.\n\n```ts\nexpect(request).toHaveUrl('/users?page=2');\nexpect(request).toHaveUrl(/^https:\\/\\/example\\.com\\/users/);\n```\n\n### `toHaveQuery`\n\nQuery values are decoded. Repeated parameters are represented as arrays.\n\n```ts\nexpect(request).toHaveQuery({\n  q: 'Ada Lovelace',\n  tag: ['math', 'code'],\n});\n```\n\n### `toRedirectTo`\n\nWithout an explicit status, any status from 300 through 399 is accepted.\n\n```ts\nexpect(response).toRedirectTo('/login');\nexpect(response).toRedirectTo('/login', 307);\n```\n\n### `toSetCookie`\n\n```ts\nexpect(response).toSetCookie('session', {\n  value: /^eyJ/,\n  path: '/',\n  httpOnly: true,\n  secure: true,\n  sameSite: 'lax',\n  maxAge: 3600,\n});\n```\n\nSupported expectations are `value`, `domain`, `path`, `expires`, `maxAge`,\n`secure`, `httpOnly`, and `sameSite`. Omitted fields are not checked.\n`domain` and `sameSite` comparisons are case-insensitive, and an obsolete\nleading dot in a domain expectation is ignored. `Date` expiration expectations\nare compared at the one-second precision provided by HTTP dates.\n\n`Set-Cookie` is intentionally supported for server-side response tests. Browsers\ndo not expose this response header to client-side JavaScript.\n\n## Why not fetch-mock?\n\nFetch mocking tools fake the server that your code calls. `expect-fetch`\nverifies the `Response` produced by the server or handler you are building.\nThey solve different problems and can be used together.\n\n## Compatibility\n\n- Node.js 20 or newer\n- Vitest 2, 3, or 4\n- Any framework using standards-compatible Fetch API objects\n\nThe matchers use structural checks rather than `instanceof Response`, allowing\nresponses created in another JavaScript realm or by compatible runtimes.\nFailure diagnostics redact `Authorization`, `Proxy-Authorization`, `Cookie`,\n`Set-Cookie`, and credential-like headers (including API key, token, secret, and\npassword) so credentials do not leak into test or CI logs.\n\n## License\n\nMIT\n\n## Contributing and security\n\nSee [CONTRIBUTING.md](./CONTRIBUTING.md) for development and release guidance.\nPlease use the private process in [SECURITY.md](./SECURITY.md) to report\nvulnerabilities.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floke-dev%2Fexpect-fetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floke-dev%2Fexpect-fetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floke-dev%2Fexpect-fetch/lists"}