{"id":16528537,"url":"https://github.com/joshuajaco/mocaron","last_synced_at":"2026-04-21T04:32:25.061Z","repository":{"id":45744419,"uuid":"514340807","full_name":"joshuajaco/mocaron","owner":"joshuajaco","description":"Simple express mock server with a flexible API inspired by fetch-mock","archived":false,"fork":false,"pushed_at":"2024-08-24T10:05:08.000Z","size":408,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-28T10:36:21.225Z","etag":null,"topics":["express","fetch-mock","mock","mock-server","mocking","mocks","server"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/mocaron","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/joshuajaco.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-15T16:48:18.000Z","updated_at":"2025-06-25T21:11:01.000Z","dependencies_parsed_at":"2024-04-18T10:42:29.542Z","dependency_job_id":"ce08f91e-6718-419f-aaf9-b6138392deff","html_url":"https://github.com/joshuajaco/mocaron","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"3d5c5cdea2050e441fceab89f95d82fb54168943"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/joshuajaco/mocaron","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshuajaco%2Fmocaron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshuajaco%2Fmocaron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshuajaco%2Fmocaron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshuajaco%2Fmocaron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joshuajaco","download_url":"https://codeload.github.com/joshuajaco/mocaron/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshuajaco%2Fmocaron/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32076928,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T02:38:07.213Z","status":"ssl_error","status_checked_at":"2026-04-21T02:38:06.559Z","response_time":128,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["express","fetch-mock","mock","mock-server","mocking","mocks","server"],"created_at":"2024-10-11T17:40:45.828Z","updated_at":"2026-04-21T04:32:25.045Z","avatar_url":"https://github.com/joshuajaco.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/joshuajaco/mocaron\"\u003e\n    \u003cimg width=\"85%\" src=\"https://raw.githubusercontent.com/joshuajaco/mocaron/main/logo.png\" alt=\"mocaron\" /\u003e\n  \u003c/a\u003e\n  \u003cbr /\u003e\n  \u003cbr /\u003e\n  \u003ca href=\"https://npmjs.com/package/mocaron\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/dw/mocaron\" alt=\"npm downloads\" /\u003e\n  \u003c/a\u003e  \n  \u003ca href=\"https://coveralls.io/github/joshuajaco/mocaron\"\u003e\n    \u003cimg src=\"https://coveralls.io/repos/github/joshuajaco/mocaron/badge.svg\" alt=\"Coverage Status\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/prettier/prettier\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square\" alt=\"code style: prettier\" /\u003e\n  \u003c/a\u003e\n  \u003cbr /\u003e\n  \u003cbr /\u003e\n  Simple \u003ca href=\"https://expressjs.com\"\u003eexpress\u003c/a\u003e mock server with a flexible API inspired by \u003ca href=\"https://www.wheresrhys.co.uk/fetch-mock\"\u003efetch-mock\u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n- [Installation](#installation)\n- [Quick Start](#quick-start)\n- [Usage](#usage)\n- [API](#api)\n- [Changelog](#changelog)\n- [License](#license)\n\n---\n\n# Installation\n\n```bash\n# npm\nnpm install -D mocaron\n\n# yarn\nyarn add -D mocaron\n\n# pnpm\npnpm add -D mocaron\n```\n\n# Quick Start\n\n```ts\nimport { MockServer } from \"mocaron\";\n\nconst mockServer = new MockServer({ port: 3000 });\n\nawait mockServer.start();\n\nmockServer.get(\"/test\", { status: 200, body: { message: \"Hello World\" } });\n\nconst response = await fetch(\"http://localhost:3000/test\");\n\nconsole.log(response.status); // 200\nconsole.log(await response.json()); // { message: \"Hello World\" }\n\nawait mockServer.stop();\n```\n\n# Usage\n\n## Starting and stopping the mock server\n\nSee [`constructor()`](#constructoroptions-mockserver) [`start()`](#start-promisevoid) [`stop()`](#stop-promisevoid)\n\n```ts\nimport { MockServer } from \"mocaron\";\n\nconst mockServer = new MockServer({ port: 3000 });\n\nawait mockServer.start();\n\n// ...\n\nawait mockServer.stop();\n```\n\n## Registering a mock\n\nRegister a mock using [`mock()`](#mockmatcher-response-options-mockserver).\n\n```ts\nmockServer.mock(\n  { path: \"/test\", method: \"GET\" },\n  { status: 200, body: { message: \"Hello World\" } },\n);\n\nconst response = await fetch(\"http://localhost:3000/test\");\n\nconsole.log(response.status); // 200\nconsole.log(await response.json()); // { message: \"Hello World\" }\n```\n\n## Method specific mocks\n\nYou can also register mocks that only match a specific HTTP method.\n\nSee [`get()`](#getmatcher-response-options-mockserver) [`post()`](#postmatcher-response-options-mockserver) [`put()`](#putmatcher-response-options-mockserver) [`patch()`](#patchmatcher-response-options-mockserver) [`delete()`](#deletematcher-response-options-mockserver)\n\n```ts\nmockServer\n  .get(\"/test\", { status: 200, body: { message: \"Hello World\" } })\n  .post(\"/test\", { status: 201, body: { message: \"Created\" } })\n  .put(\"/test\", { status: 200, body: { message: \"Replaced\" } })\n  .patch(\"/test\", { status: 200, body: { message: \"Updated\" } })\n  .delete(\"/test\", { status: 204 });\n```\n\n## Unmatched requests\n\nIf a request does not match any of the registered mocks the server will respond with a 404 status code.\n\n```ts\nconst response = await fetch(\"http://localhost:3000/test\");\n\nconsole.log(response.status); // 404\n```\n\n## Ambiguous mocks\n\nIf two or more mocks match the same request the server will respond with a 404 status code.\n\n```ts\nmockServer.mock({ path: \"/foo\" }, \"foo\").mock({ path: \"/foo\" }, \"bar\");\n\nconst response = await fetch(\"http://localhost:3000/foo\");\n\nconsole.log(response.status); // 404\n```\n\nYou can override this behavior by passing the [`overwrite`](#mockoptions) option to the last matching mock.\n\n```ts\nmockServer\n  .mock({ path: \"/foo\" }, \"foo\")\n  .mock({ path: \"/foo\" }, \"bar\", { overwrite: true });\n\nconst response = await fetch(\"http://localhost:3000/foo\");\n\nconsole.log(response.status); // 200\nconsole.log(await response.text()); // bar\n```\n\n## Resetting the mock server\n\nCalling [`reset()`](#reset-void) will reset the mock server to its initial state.\n\n```ts\nmockServer.get(\"/test\", { status: 200 });\n\nlet response = await fetch(\"http://localhost:3000/test\");\nconsole.log(response.status); // 200\n\nmockServer.reset();\n\nresponse = await fetch(\"http://localhost:3000/test\");\nconsole.log(response.status); // 404\n```\n\n## Testing\n\nSet up the mock server for each test using [`start()`](#start-promisevoid), [`stop()`](#stop-promisevoid) and [`reset()`](#reset-void).\n\n```ts\nimport { MockServer } from \"mocaron\";\nimport { beforeAll, afterAll, beforeEach, test, assert } from \"my-test-library\";\n\nconst mockServer = new MockServer({ port: 3000 });\n\nbeforeAll(() =\u003e mockServer.start());\nafterAll(() =\u003e mockServer.stop());\nbeforeEach(() =\u003e mockServer.reset());\n```\n\nTest that a mock has been called using [`hasBeenCalledWith()`](#hasbeencalledwithmatcher-boolean).\n\n```ts\ntest(\"mock has been called\", async () =\u003e {\n  mockServer.get(\"/test\", { status: 200 });\n\n  await fetch(\"http://localhost:3000/test\");\n\n  assert(mockServer.hasBeenCalledWith({ path: \"/test\" }));\n});\n```\n\nTest that a mock has been called a specific number of times using [`hasBeenCalledTimes()`](#hasbeencalledtimestimes-matcher-boolean).\n\n```ts\ntest(\"mock has been called 3 times\", async () =\u003e {\n  mockServer.get(\"/test\", { status: 200 });\n\n  await fetch(\"http://localhost:3000/test\");\n  await fetch(\"http://localhost:3000/test\");\n  await fetch(\"http://localhost:3000/test\");\n\n  assert(mockServer.hasBeenCalledTimes(3, { path: \"/test\" }));\n});\n```\n\nCustom assertions using [`calls()`](#calls-readonly-call).\n\n```ts\ntest(\"custom assertion\", async () =\u003e {\n  mockServer.get(\"/test\", { status: 200 });\n\n  await fetch(\"http://localhost:3000/test\");\n\n  assert(mockServer.calls().length === 1);\n  assert(mockServer.calls()[0].request.path === \"/test\");\n});\n```\n\n# API\n\n- [`MockServer`](#mockserver)\n  - [`constructor()`](#constructoroptions-mockserver)\n  - [`start()`](#start-promisevoid)\n  - [`stop()`](#stop-promisevoid)\n  - [`port()`](#port-number)\n  - [`mock()`](#mockmatcher-response-options-mockserver)\n  - [`get()`](#getmatcher-response-options-mockserver)\n  - [`post()`](#postmatcher-response-options-mockserver)\n  - [`put()`](#putmatcher-response-options-mockserver)\n  - [`patch()`](#patchmatcher-response-options-mockserver)\n  - [`delete()`](#deletematcher-response-options-mockserver)\n  - [`mocks()`](#mocks-readonly-mock)\n  - [`calls()`](#calls-readonly-call)\n  - [`hasBeenCalledWith()`](#hasbeencalledwithmatcher-boolean)\n  - [`hasBeenCalledTimes()`](#hasbeencalledtimestimes-matcher-boolean)\n  - [`countCalls()`](#countcallsmatcher-number)\n  - [`reset()`](#reset-void)\n  - [`resetMocks()`](#resetmocks-void)\n  - [`resetCalls()`](#resetcalls-void)\n- [`ExpectationMessage`](#expectationmessage)\n  - [`hasBeenCalledWith()`](#hasbeencalledwithmockserver-matcher-string)\n  - [`hasBeenCalledTimes()`](#hasbeencalledtimesmockserver-times-matcher-string)\n- [`Options`](#options)\n- [`Request`](#request)\n- [`Matcher`](#matcher)\n- [`MatcherObj`](#matcherobj)\n- [`MatcherFn`](#matcherfn)\n- [`Response`](#response)\n- [`ResponseObj`](#responseobj)\n- [`ResponseFn`](#responsefn)\n- [`MockOptions`](#mockoptions)\n- [`Mock`](#mock)\n- [`Call`](#call)\n\n## `MockServer`\n\n### `constructor(options): MockServer`\n\nCreate a new [`MockServer`](#mockserver) instance.\n\n| Param   | Type                  | Default |\n| ------- | --------------------- | ------- |\n| options | [`Options`](#options) | -       |\n\n#### Example\n\n```ts\nconst mockServer = new MockServer({ port: 3000 });\n```\n\n---\n\n### `start(): Promise\u003cvoid\u003e`\n\nStart the mock server.\n\n#### Example\n\n```ts\nawait mockServer.start();\n```\n\n---\n\n### `stop(): Promise\u003cvoid\u003e`\n\nStop the mock server.\n\n#### Example\n\n```ts\nawait mockServer.stop();\n```\n\n---\n\n### `port(): number`\n\nGet the port the mock server is running on.\n\n#### Example\n\n```ts\nconst port = mockServer.port();\nconsole.log(port); // 3000\n```\n\n---\n\n### `mock(matcher, response, options): MockServer`\n\nRegister a mock.\n\n| Param    | Type                                            | Default |\n| -------- | ----------------------------------------------- | ------- |\n| matcher  | `string` \\| `RegExp` \\| [`Matcher`](#matcher)   | -       |\n| response | `string` \\| `number` \\| [`Response`](#response) | -       |\n| options  | [`MockOptions`](#mockoptions)                   | `{}`    |\n\nIf `matcher` is a `string` or `RegExp`, it will be used to match the request path.  \nIf `response` is a `string`, it will be used as the response body.  \nIf `response` is a `number`, it will be used as the response status code.\n\nReturns the [`MockServer`](#mockserver) instance.\n\n#### Example\n\n```ts\nmockServer.mock({ path: \"/test\" }, { status: 204 });\n\nconst response = await fetch(\"http://localhost:3000/test\");\n\nconsole.log(response.status); // 204\n```\n\n---\n\n### `get(matcher, response, options): MockServer`\n\nRegister a mock that only responds to requests using the HTTP `GET` method.\n\n| Param    | Type                                                | Default |\n| -------- | --------------------------------------------------- | ------- |\n| matcher  | `string` \\| `RegExp` \\| [`MatcherObj`](#matcherobj) | -       |\n| response | `string` \\| `number` \\| [`Response`](#response)     | -       |\n| options  | [`MockOptions`](#mockoptions)                       | `{}`    |\n\nIf `matcher` is a `string` or `RegExp`, it will be used to match the request path.  \nIf `response` is a `string`, it will be used as the response body.  \nIf `response` is a `number`, it will be used as the response status code.\n\nReturns the [`MockServer`](#mockserver) instance.\n\n#### Example\n\n```ts\nmockServer.get(\"/test\", {\n  status: 200,\n  body: { message: \"Hello World\" },\n});\n\nconst response = await fetch(\"http://localhost:3000/test\");\n\nconsole.log(response.status); // 200\nconsole.log(await response.json()); // { message: \"Hello World\" }\n```\n\n---\n\n### `post(matcher, response, options): MockServer`\n\nRegister a mock that only responds to requests using the HTTP `POST` method.\n\n| Param    | Type                                                | Default |\n| -------- | --------------------------------------------------- | ------- |\n| matcher  | `string` \\| `RegExp` \\| [`MatcherObj`](#matcherobj) | -       |\n| response | `string` \\| `number` \\| [`Response`](#response)     | -       |\n| options  | [`MockOptions`](#mockoptions)                       | `{}`    |\n\nIf `matcher` is a `string` or `RegExp`, it will be used to match the request path.  \nIf `response` is a `string`, it will be used as the response body.  \nIf `response` is a `number`, it will be used as the response status code.\n\nReturns the [`MockServer`](#mockserver) instance.\n\n#### Example\n\n```ts\nmockServer.post(\"/test\", {\n  status: 201,\n  body: { message: \"Hello World\" },\n});\n\nconst response = await fetch(\"http://localhost:3000/test\", {\n  method: \"POST\",\n  body: JSON.stringify({ message: \"Hello World\" }),\n});\n\nconsole.log(response.status); // 201\nconsole.log(await response.json()); // { message: \"Hello World\" }\n```\n\n---\n\n### `put(matcher, response, options): MockServer`\n\nRegister a mock that only responds to requests using the HTTP `PUT` method.\n\n| Param    | Type                                                | Default |\n| -------- | --------------------------------------------------- | ------- |\n| matcher  | `string` \\| `RegExp` \\| [`MatcherObj`](#matcherobj) | -       |\n| response | `string` \\| `number` \\| [`Response`](#response)     | -       |\n| options  | [`MockOptions`](#mockoptions)                       | `{}`    |\n\nIf `matcher` is a `string` or `RegExp`, it will be used to match the request path.  \nIf `response` is a `string`, it will be used as the response body.  \nIf `response` is a `number`, it will be used as the response status code.\n\nReturns the [`MockServer`](#mockserver) instance.\n\n#### Example\n\n```ts\nmockServer.put(\"/test\", {\n  status: 200,\n  body: { message: \"Hello World\" },\n});\n\nconst response = await fetch(\"http://localhost:3000/test\", {\n  method: \"PUT\",\n  body: JSON.stringify({ message: \"Hello World\" }),\n});\n\nconsole.log(response.status); // 200\nconsole.log(await response.json()); // { message: \"Hello World\" }\n```\n\n---\n\n### `patch(matcher, response, options): MockServer`\n\nRegister a mock that only responds to requests using the HTTP `PATCH` method.\n\n| Param    | Type                                                | Default |\n| -------- | --------------------------------------------------- | ------- |\n| matcher  | `string` \\| `RegExp` \\| [`MatcherObj`](#matcherobj) | -       |\n| response | `string` \\| `number` \\| [`Response`](#response)     | -       |\n| options  | [`MockOptions`](#mockoptions)                       | `{}`    |\n\nIf `matcher` is a `string` or `RegExp`, it will be used to match the request path.  \nIf `response` is a `string`, it will be used as the response body.  \nIf `response` is a `number`, it will be used as the response status code.\n\nReturns the [`MockServer`](#mockserver) instance.\n\n#### Example\n\n```ts\nmockServer.patch(\"/test\", {\n  status: 200,\n  body: { message: \"Hello World\" },\n});\n\nconst response = await fetch(\"http://localhost:3000/test\", {\n  method: \"PATCH\",\n  body: JSON.stringify({ message: \"Hello World\" }),\n});\n\nconsole.log(response.status); // 200\nconsole.log(await response.json()); // { message: \"Hello World\" }\n```\n\n---\n\n### `delete(matcher, response, options): MockServer`\n\nRegister a mock that only responds to requests using the HTTP `DELETE` method.\n\n| Param    | Type                                                | Default |\n| -------- | --------------------------------------------------- | ------- |\n| matcher  | `string` \\| `RegExp` \\| [`MatcherObj`](#matcherobj) | -       |\n| response | `string` \\| `number` \\| [`Response`](#response)     | -       |\n| options  | [`MockOptions`](#mockoptions)                       | `{}`    |\n\nIf `matcher` is a `string` or `RegExp`, it will be used to match the request path.  \nIf `response` is a `string`, it will be used as the response body.  \nIf `response` is a `number`, it will be used as the response status code.\n\nReturns the [`MockServer`](#mockserver) instance.\n\n#### Example\n\n```ts\nmockServer.delete(\"/test\", { status: 204 });\n\nconst response = await fetch(\"http://localhost:3000/test\", {\n  method: \"DELETE\",\n});\n\nconsole.log(response.status); // 204\n```\n\n---\n\n### `mocks(): readonly Mock[]`\n\nGet all registered mocks.\n\nReturns an array of [`Mock`](#mock) objects.\n\n#### Example\n\n```ts\nmockServer.mock({ path: \"/test\" }, { status: 204 });\n\nconst mocks = mockServer.mocks();\n\nconsole.log(mocks);\n// [{ matcher: { path: \"/test\" }, response: { status: 204 } }]\n```\n\n---\n\n### `calls(): readonly Call[]`\n\nGet all registered calls.\n\nReturns an array of [`Call`](#call) objects.\n\n#### Example\n\n```ts\nmockServer.mock({ path: \"/test\" }, { status: 204 });\nawait fetch(\"http://localhost:3000/test\");\n\nconst calls = mockServer.calls();\n\nconsole.log(calls);\n// [{ matcher: { path: \"/test\" }, request: \u003cexpress.Request\u003e }]\n```\n\n---\n\n### `hasBeenCalledWith(matcher): boolean`\n\nCheck if the route has been called with the given `matcher`.\n\n| Param   | Type                                          | Default |\n| ------- | --------------------------------------------- | ------- |\n| matcher | `string` \\| `RegExp` \\| [`Matcher`](#matcher) | -       |\n\nIf `matcher` is a `string` or `RegExp`, it will be used to match the request path.\n\nReturns `true` if the route has been called with the given `matcher`, `false` otherwise.\n\n#### Example\n\n```ts\nmockServer.get(\"/test\", { status: 200 });\n\nconsole.log(mockServer.hasBeenCalledWith({ path: \"/test\" })); // false\n\nawait fetch(\"http://localhost:3000/test\");\n\nconsole.log(mockServer.hasBeenCalledWith({ path: \"/test\" })); // true\n```\n\n---\n\n### `hasBeenCalledTimes(times, matcher): boolean`\n\nCheck if the route has been called a certain number of times with the given `matcher`.\n\n| Param   | Type                                          | Default |\n| ------- | --------------------------------------------- | ------- |\n| times   | `number`                                      | -       |\n| matcher | `string` \\| `RegExp` \\| [`Matcher`](#matcher) | -       |\n\nIf `matcher` is a `string` or `RegExp`, it will be used to match the request path.\n\nReturns `true` if the route has been called `times` times with the given `matcher`, `false` otherwise.\n\n#### Example\n\n```ts\nmockServer.get(\"/test\", { status: 200 });\n\nconsole.log(mockServer.hasBeenCalledTimes(0, { path: \"/test\" })); // true\nconsole.log(mockServer.hasBeenCalledTimes(1, { path: \"/test\" })); // false\n\nawait fetch(\"http://localhost:3000/test\");\n\nconsole.log(mockServer.hasBeenCalledTimes(0, { path: \"/test\" })); // false\nconsole.log(mockServer.hasBeenCalledTimes(1, { path: \"/test\" })); // true\n```\n\n---\n\n### `countCalls(matcher): number`\n\nCount the number of times the server was called with the given `matcher`.\n\n| Param   | Type                                          | Default |\n| ------- | --------------------------------------------- | ------- |\n| matcher | `string` \\| `RegExp` \\| [`Matcher`](#matcher) | -       |\n\nIf `matcher` is a `string` or `RegExp`, it will be used to match the request path.\n\nReturns the number of times the server has been called with the given `matcher`.\n\n#### Example\n\n```ts\nmockServer.get(\"/test\", { status: 200 });\n\nconsole.log(mockServer.countCalls({ path: \"/test\" })); // 0\n\nawait fetch(\"http://localhost:3000/test\");\n\nconsole.log(mockServer.countCalls({ path: \"/test\" })); // 1\n```\n\n---\n\n### `reset(): void`\n\nReset all mocks and calls.\n\n#### Example\n\n```ts\nmockServer.get(\"/test\", { status: 200 });\nawait fetch(\"http://localhost:3000/test\");\n\nconsole.log(mockServer.mocks());\n// [{ matcher: { path: \"/test\", method: \"GET\" }, response: { status: 200 } }]\n\nconsole.log(mockServer.calls());\n// [{ matcher: { path: \"/test\", method: \"GET\" }, request: \u003cexpress.Request\u003e }]\n\nmockServer.reset();\n\nconsole.log(mockServer.mocks()); // []\nconsole.log(mockServer.calls()); // []\n```\n\n---\n\n### `resetMocks(): void`\n\nReset all mocks.\n\n#### Example\n\n```ts\nmockServer.get(\"/test\", { status: 200 });\n\nconsole.log(mockServer.mocks());\n// [{ matcher: { path: \"/test\", method: \"GET\" }, response: { status: 200 } }]\n\nmockServer.resetMocks();\n\nconsole.log(mockServer.mocks()); // []\n```\n\n---\n\n### `resetCalls(): void`\n\nReset all calls.\n\n#### Example\n\n```ts\nmockServer.get(\"/test\", { status: 200 });\nawait fetch(\"http://localhost:3000/test\");\n\nconsole.log(mockServer.calls());\n// [{ matcher: { path: \"/test\", method: \"GET\" }, request: \u003cexpress.Request\u003e }]\n\nmockServer.resetCalls();\n\nconsole.log(mockServer.calls()); // []\n```\n\n## `ExpectationMessage`\n\n### `hasBeenCalledWith(mockServer, matcher): string`\n\nFormat an expectation message for [`hasBeenCalledWith()`](#hasbeencalledwithmatcher-boolean).\n\n| Param      | Type                        | Default |\n| ---------- | --------------------------- | ------- |\n| mockServer | [`MockServer`](#mockserver) | -       |\n| matcher    | [`Matcher`](#matcher)       | -       |\n\nReturns a string with the formatted expectation message.\n\n#### Example\n\n```ts\nif (!mockServer.hasBeenCalledWith(matcher)) {\n  throw new Error(ExpectationMessage.hasBeenCalledWith(mockServer, matcher));\n}\n```\n\n### `hasBeenCalledTimes(mockServer, times, matcher): string`\n\nFormat an expectation message for [`hasBeenCalledTimes()`](#hasbeencalledtimestimes-matcher-boolean).\n\n| Param      | Type                        | Default |\n| ---------- | --------------------------- | ------- |\n| mockServer | [`MockServer`](#mockserver) | -       |\n| times      | number                      | -       |\n| matcher    | [`Matcher`](#matcher)       | -       |\n\nReturns a string with the formatted expectation message.\n\n#### Example\n\n```ts\nif (!mockServer.hasBeenCalledTimes(mockServer, 2, matcher)) {\n  throw new Error(\n    ExpectationMessage.hasBeenCalledTimes(mockServer, 2, matcher),\n  );\n}\n```\n\n## `Options`\n\nObject with the following properties:\n\n| Property | Type     | Description                    |\n| -------- | -------- | ------------------------------ |\n| port     | `number` | port to run the mock server on |\n\n## `Request`\n\nType alias for [`express.Request`](https://expressjs.com/en/4x/api.html#req) with the `body` property typed as `Buffer` | `undefined`.\n\n```ts\ntype Request = express.Request\u003c{}, unknown, Buffer | undefined\u003e;\n```\n\n## `Matcher`\n\nType alias for [`MatcherObj`](#matcherobj) | [`MatcherFn`](#matcherfn).\n\n```ts\ntype Matcher = MatcherObj | MatcherFn;\n```\n\n## `MatcherObj`\n\nObject with the following properties:\n\n| Property | Type                                                                                | Description                                                                                                   |\n| -------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |\n| method   | `string` \\| `undefined`                                                             | HTTP method to match against                                                                                  |\n| path     | `string` \\| `RegExp` \\| `undefined`                                                 | path to match against                                                                                         |\n| query    | [`Request[\"query\"]`](https://expressjs.com/en/4x/api.html#req.query) \\| `undefined` | query parameters to match against.\u003cbr/\u003eParameters explicitly set to `undefined` will not match when provided. |\n| headers  | `Record\u003cstring, string \\| undefined\u003e` \\| `undefined`                                | headers to match against.\u003cbr/\u003eHeaders explicitly set to `undefined` will not match when provided.             |\n| body     | `string` \\| `object` \\| `undefined`                                                 | body to match against.\u003cbr/\u003eIf an `object` is given it will be compared to the request body parsed as JSON.    |\n\n## `MatcherFn`\n\nFunction that takes a [`Request`](#request) and returns whether the request should match.\n\n```ts\ntype MatcherFn = (req: Request) =\u003e boolean;\n```\n\n## `Response`\n\nType alias for [`ResponseObj`](#responseobj) | [`ResponseFn`](#responsefn).\n\n```ts\ntype Response = ResponseObj | ResponseFn;\n```\n\n## `ResponseObj`\n\nObject with the following properties:\n\n| Property | Type                                    | Description                                                                              |\n| -------- | --------------------------------------- | ---------------------------------------------------------------------------------------- |\n| status   | `number` \\| `undefined`                 | status code to respond with (defaults to `200`)                                          |\n| headers  | `Record\u003cstring, string\u003e` \\| `undefined` | headers to respond with                                                                  |\n| body     | `string` \\| `object` \\| `undefined`     | body to respond with.\u003cbr/\u003eIf an `object` is given it will be converted to a JSON string. |\n| delay    | `number` \\| `undefined`                 | delay in milliseconds before responding                                                  |\n\n## `ResponseFn`\n\nFunction or async function that takes a [`Request`](#request) and returns a [`ResponseObj`](#responseobj).\n\n```ts\ntype ResponseFn = (req: Request) =\u003e ResponseObj | Promise\u003cResponseObj\u003e;\n```\n\n## `MockOptions`\n\nObject with the following properties:\n\n| Property  | Type                     | Description                                                                                                        |\n| --------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------ |\n| overwrite | `boolean` \\| `undefined` | when set to `true`,\u003cbr/\u003eprevious [ambiguous mocks](#ambiguous-mocks) matching the same request will be overwritten |\n\n## `Mock`\n\nObject with the following properties:\n\n| Property | Type                          | Description                                        |\n| -------- | ----------------------------- | -------------------------------------------------- |\n| matcher  | [`Matcher`](#matcher)         | matcher to match against the request               |\n| response | [`Response`](#response)       | response the server will respond with when matched |\n| options  | [`MockOptions`](#mockoptions) | see [`MockOptions`](#mockoptions)                  |\n\n## `Call`\n\nObject with the following properties:\n\n| Property | Type                  | Description                         |\n| -------- | --------------------- | ----------------------------------- |\n| request  | [`Request`](#request) | request the server was called with  |\n| matcher  | [`Matcher`](#matcher) | matcher the request matched against |\n\n# Changelog\n\n[CHANGELOG.md](https://github.com/joshuajaco/mocaron/blob/main/CHANGELOG.md)\n\n# License\n\n[MIT](https://github.com/joshuajaco/mocaron/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshuajaco%2Fmocaron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshuajaco%2Fmocaron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshuajaco%2Fmocaron/lists"}