Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: wheresrhys/fetch-mock
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: fetch-mock-v12.4.0
Choose a base ref
...
head repository: wheresrhys/fetch-mock
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: fetch-mock-v12.5.1
Choose a head ref
  • 18 commits
  • 18 files changed
  • 2 contributors

Commits on Feb 28, 2025

  1. Copy the full SHA
    db6aba5 View commit details

Commits on Mar 1, 2025

  1. Copy the full SHA
    ab7dff4 View commit details
  2. chore: fix typings

    wheresrhys committed Mar 1, 2025
    Copy the full SHA
    8754139 View commit details
  3. docs: document support or FormData

    wheresrhys committed Mar 1, 2025
    Copy the full SHA
    5df179c View commit details
  4. Merge pull request #916 from wheresrhys/rhys/match-form-data

    Rhys/match form data
    wheresrhys authored Mar 1, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    7e53c80 View commit details
  5. chore: release main

    github-actions[bot] authored Mar 1, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    78575b8 View commit details
  6. Merge pull request #917 from wheresrhys/release-please--branches--main

    chore: release main
    wheresrhys authored Mar 1, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    42e8cca View commit details
  7. docs: Add FormData type to body matcher docs

    wheresrhys authored Mar 1, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a9ec9b7 View commit details
  8. build(deps-dev): bumped vitest

    wheresrhys committed Mar 1, 2025
    Copy the full SHA
    0c1a0b8 View commit details
  9. fix: improve handling of abort

    wheresrhys committed Mar 1, 2025
    Copy the full SHA
    5c1085d View commit details
  10. Merge pull request #918 from wheresrhys/rhys/abort-midstream-3

    fix: improve handling of abort
    wheresrhys authored Mar 1, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c9d7eb2 View commit details
  11. fix: remove deprecated is-subset-of

    wheresrhys committed Mar 1, 2025
    Copy the full SHA
    a2546ef View commit details
  12. docs: remobve is-subset-of from docs

    wheresrhys committed Mar 1, 2025
    Copy the full SHA
    0af2aa4 View commit details
  13. chore: lint

    wheresrhys committed Mar 1, 2025
    Copy the full SHA
    aa548e9 View commit details
  14. chore: lint

    wheresrhys committed Mar 1, 2025
    Copy the full SHA
    7877887 View commit details
  15. Merge pull request #920 from wheresrhys/rhys/is-subset-of

    fix: remove deprecated is-subset-of
    wheresrhys authored Mar 1, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    62bc8d3 View commit details
  16. chore: release main

    github-actions[bot] authored Mar 1, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    59dd040 View commit details
  17. Merge pull request #919 from wheresrhys/release-please--branches--main

    chore: release main
    wheresrhys authored Mar 1, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    51777ec View commit details
6 changes: 3 additions & 3 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"packages/fetch-mock": "12.4.0",
"packages/vitest": "0.2.10",
"packages/jest": "0.2.12",
"packages/fetch-mock": "12.5.1",
"packages/vitest": "0.2.12",
"packages/jest": "0.2.14",
"packages/codemods": "0.1.3"
}
13 changes: 9 additions & 4 deletions docs/docs/API/route/matcher.md
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ All of the following can be passed in directly as the `matcher` argument or as t
`fetch` and other standards have strong opinions about how to interpret URLs. `fetch-mock` attempts to respect these, which can lead to unexpected behaviour. The notes below apply to all types of url matcher.

1. Trailing slashes are ignored i.e. `http://thing` is treated the same as `http://thing/` ([read the spec](https://url.spec.whatwg.org/#url-equivalence))
2. When using dot segments in urls `fetch-mock` will match both the full path containing dot segments, and the path ot resolves to e.g. `/path/../other-path` will match `/path/../other-path` and `/other-path` ([read the spec](https://github.com/wheresrhys/fetch-mock/issues/763#:~:text=resolved%20as%20per-,the%20spec,-before%20attempting%20to))
2. When using dot segments in urls `fetch-mock` will match both the full path containing dot segments, and the path it resolves to e.g. `/path/../other-path` will match `/path/../other-path` and `/other-path` ([read the spec](https://github.com/wheresrhys/fetch-mock/issues/763#:~:text=resolved%20as%20per-,the%20spec,-before%20attempting%20to))
3. `fetch` will convert any protocol-relative urls to ones using the protocol of the current page e.g. if the browser is at `**http:**//a.com` and your application calls `fetch('//some.url')`, a request will be made to `**http:**//some.url`. However, to discourage writing tests that pass in one environment but not another, `fetch-mock` **will only** match requests where the protocol (or lack of) is exactly the same as the route. e.g. `begin://a.com` will match `//a.com/path` but not `http://a.com/path`
4. Fetches of relative urls e.g. `fetch('image.jg')` or `fetch('/path')` are technically not supported in node.js at all. However, `fetch-mock` will handle them if either
a) The global `fetch-mock` option `fetchMock.config.allowRelativeUrls = true` is set
@@ -151,13 +151,18 @@ Match only requests that have these query parameters set (in any order). Query p

### body

`{Object}`
`{Object|FormData}`

Match only requests that send a JSON body with the exact structure and properties as the one provided here.
Match only requests that send a body with the exact structure and properties as the one provided here. `JSON` or `FormData` instances can be used, but a route set up with a `JSON` body will not match requests where the data is sent as `FormData`, and vice versa.

Note that if matching on body _and_ using `Request` instances in your source code, this forces fetch-mock into an asynchronous flow _before_ it is able to route requests effectively. This means no [call history methods](/fetch-mock/docs/API/CallHistory) can be used synchronously. You must first either await the fetches to resolve, or `await fetchMock.callHistory.flush()`. The popular library [Ky](https://github.com/sindresorhus/ky) uses `Request` instances internally, and so also triggers this mode.

e.g.`{body: { "key1": "value1", "key2": "value2" }}`
e.g.

```js
{body: { "key1": "value1", "key2": "value2" }}
new FormData(document.querySelector('#login'))
```

#### matchPartialBody

2 changes: 1 addition & 1 deletion docs/docs/Usage/configuration.md
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ Sets a `Content-Length` header on each response, with the exception of responses

`{Boolean}` default: `false`

Match calls that only partially match a specified body json. Uses the [is-subset](https://www.npmjs.com/package/is-subset) library under the hood, which implements behaviour the same as jest's [.objectContaining()](https://jestjs.io/docs/en/expect#expectobjectcontainingobject) method.
Match calls that only partially match a specified body json or FormData.

### allowRelativeUrls<sup>†</sup>

Loading