Skip to content

Commit

Permalink
docs: add note about relative URLs to upgrade guide
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Nov 8, 2024
1 parent 069a070 commit e1bbcad
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions docs/docs/Usage/upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,27 @@ The [@fetch-mock/codemods](https://www.npmjs.com/package/@fetch-mock/codemods) l

## Summary of changes

### Uses global, native `fetch` implementation in all environments

Previously this was true in browsers, but in node.js the node-fetch library was used.

### `.mock()` method removed

This combined adding a route with mocking the global instance of `fetch`. These are now split into 2 methods: `.route()` and `.mockGlobal()`.

## Reset methods changed
### Reset methods changed

`.reset()`, `.restore()`, `.resetBehavior()` and `.resetHistory()` have been removed and replaced with [methods that are more granular and clearly named](/fetch-mock/docs/API/resetting). Note that the [jest](/fetch-mock/docs/wrappers/jest) and [vitest](/fetch-mock/docs/wrappers/vitest) wrappers for fetch-mock still implement `.mockClear()`, `mockReset()` and `mockRestore()`.

## Call history methods changed
### Call history methods changed

The filtering behaviour has been rewritten around named routes, and methods return CallLog objects that contain far more metadata about the call. [Call history docs](/fetch-mock/docs/API/CallHistory)

## Some convenience routing methods removed
### Relative URLs not permitted by default in Node.js

A consequence of shifting to use the native implementation of the URL class is that relative URLs are no longer permissable when running tests in node.js, but [this can easily be enabled](https://www.wheresrhys.co.uk/fetch-mock/docs/Usage/configuration#allowrelativeurls).

### Some convenience routing methods removed

`getOnce()` and `getAnyOnce()` have been removed, but the behaviour can still be implemented by the user as follows:

Expand All @@ -29,13 +37,13 @@ The filtering behaviour has been rewritten around named routes, and methods retu

The same is true for `postOnce()`, `deleteOnce()` etc.

## Options removed
### Options removed

- `overwriteRoutes` - this reflects that multiple routes using the same underlying matcher but different options no longer throw an error.
- `warnOnFallback` - given the improved state of node.js debugging tools compared to when fetch-mock was first written, this debugging utilty has been removed.
- `sendAsJson` - fetch-mock@12 implements streams more robustly than previous options, so the user no longer needs to flag when an object response should be converted to JSON.
- `fallbackToNetwork` - The [`spyGlobal()` method](/fetch-mock/docs/API/mocking-and-spying#spyglobal) should now be used.

## `sandbox()` method removed
### `sandbox()` method removed

This was principally used when mocking node-fetch referenced as a local variable. Given that `fetch` is now available as a native global it's less useful and has been removed. If necessary to mock a local instance of node-fetch use [`.fetchHandler`](/fetch-mock/docs/API/mocking-and-spying#fetchhandler)

0 comments on commit e1bbcad

Please sign in to comment.