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-v10.1.1
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-v11.0.0
Choose a head ref

Commits on Jul 23, 2024

  1. Copy the full SHA
    7417c1a View commit details
  2. Copy the full SHA
    10ec8af View commit details
  3. refactor!: defined route shorthand methods more declaratively

    have also removed {method}Any and {method}AnyOnce - not all that useful
    wheresrhys committed Jul 23, 2024
    Copy the full SHA
    f42d240 View commit details
  4. Copy the full SHA
    289f980 View commit details
  5. Copy the full SHA
    a17d857 View commit details

Commits on Jul 24, 2024

  1. Copy the full SHA
    a650023 View commit details
  2. Copy the full SHA
    f8c1168 View commit details
  3. chore: linted

    wheresrhys committed Jul 24, 2024
    Copy the full SHA
    6c21822 View commit details
  4. Merge pull request #738 from wheresrhys/rhys/types3

    Rhys/types3
    wheresrhys authored Jul 24, 2024
    Copy the full SHA
    4e46676 View commit details
  5. Copy the full SHA
    177ded9 View commit details
  6. Merge pull request #740 from wheresrhys/rhys/chores

    chore: addressed a few trivial todos
    wheresrhys authored Jul 24, 2024
    Copy the full SHA
    020948d View commit details
  7. chore: release main

    github-actions[bot] authored and wheresrhys committed Jul 24, 2024
    Copy the full SHA
    dae3605 View commit details
  8. Update CHANGELOG.md

    wheresrhys committed Jul 24, 2024
    Copy the full SHA
    ae7edca View commit details
  9. Copy the full SHA
    c459dba View commit details
  10. Copy the full SHA
    219dab3 View commit details
  11. Copy the full SHA
    032d4ea View commit details
  12. Copy the full SHA
    db6b0b0 View commit details
  13. Copy the full SHA
    db8129d View commit details
  14. Copy the full SHA
    f47a4a2 View commit details
  15. build: share rollup config

    wheresrhys committed Jul 24, 2024
    Copy the full SHA
    6d4b0a5 View commit details
  16. Copy the full SHA
    731b734 View commit details
  17. Copy the full SHA
    c2cd7ee View commit details
  18. Copy the full SHA
    a343062 View commit details
  19. chore: lint rollup config

    wheresrhys committed Jul 24, 2024
    Copy the full SHA
    87a2288 View commit details
  20. Copy the full SHA
    4a0a376 View commit details
  21. chore: fixed newly arisen type errors

    in particular, switched dependency is-subset for newer, is-subset-of library
    wheresrhys committed Jul 24, 2024
    Copy the full SHA
    d2f7eeb View commit details
  22. fix: force releasing core

    wheresrhys committed Jul 24, 2024
    Copy the full SHA
    1c8fdfc View commit details
  23. Copy the full SHA
    0afbb52 View commit details
  24. Copy the full SHA
    1e12c1c View commit details
  25. Copy the full SHA
    06c86e5 View commit details
  26. Copy the full SHA
    8ec57ac View commit details
  27. Merge pull request #747 from wheresrhys/rhys/query-params-access

    refactor: remove query string dependency
    wheresrhys authored Jul 24, 2024
    Copy the full SHA
    0132ec6 View commit details
  28. Copy the full SHA
    26b3e73 View commit details
  29. Copy the full SHA
    d1ce46c View commit details
  30. fix: make a more sensible decision about matching body

    ignore bodies sent in HEAD, GET and DELETE
    wheresrhys committed Jul 24, 2024
    Copy the full SHA
    0ef50d6 View commit details
  31. Copy the full SHA
    ec6b47d View commit details
  32. Merge pull request #749 from wheresrhys/rhys/body-call-inspection

    fix: make a more sensible decision about matching body
    wheresrhys authored Jul 24, 2024
    Copy the full SHA
    c11d7aa View commit details
  33. Copy the full SHA
    79a84d5 View commit details
  34. Copy the full SHA
    741fc13 View commit details
  35. Copy the full SHA
    c640f24 View commit details
  36. Copy the full SHA
    c83d9f9 View commit details
  37. Copy the full SHA
    45eadd7 View commit details

Commits on Jul 25, 2024

  1. Merge pull request #752 from wheresrhys/rhys/response-error

    test: added test for Response.error()
    wheresrhys authored Jul 25, 2024
    Copy the full SHA
    657ff1f View commit details
  2. Merge pull request #753 from wheresrhys/rhys/multiple-url-matchers

    feat: support multiple url matchers at once
    wheresrhys authored Jul 25, 2024
    Copy the full SHA
    9440b01 View commit details
  3. test: refactor abort tests

    wheresrhys committed Jul 25, 2024
    Copy the full SHA
    c3548a5 View commit details
  4. Copy the full SHA
    aa3b899 View commit details
  5. Merge pull request #750 from wheresrhys/rhys/abort-body

    fix: abort request and response bodies
    wheresrhys authored Jul 25, 2024
    Copy the full SHA
    7dc6979 View commit details
  6. Copy the full SHA
    8ba07c3 View commit details
  7. Copy the full SHA
    bc4e4ef View commit details
  8. Copy the full SHA
    97b8dd5 View commit details
Showing with 2,548 additions and 2,831 deletions.
  1. +19 −4 .circleci/config.yml
  2. +5 −1 .gitignore
  3. +1 −1 .husky/pre-commit
  4. +1 −0 .prettierignore
  5. +2 −2 .release-please-manifest.json
  6. +8 −0 docs/blog/2024-07-21-introducing-core.md
  7. +26 −0 docs/blog/2024-07-24-esm-and-commonjs.md
  8. +9 −8 docs/docs/@fetch-mock/core/CallHistory.md
  9. +18 −0 docs/docs/@fetch-mock/core/index.md
  10. +29 −0 docs/docs/@fetch-mock/core/mocking-and-spying.md
  11. +1 −13 docs/docs/@fetch-mock/core/more-routing-methods.md
  12. +4 −0 docs/docs/@fetch-mock/core/resetting.md
  13. +23 −3 docs/docs/@fetch-mock/core/route/matcher.md
  14. +4 −2 docs/docs/fetch-mock/Usage/versions.md
  15. +10 −0 import-compat/package.json
  16. +7 −0 import-compat/ts-cjs.ts
  17. +7 −0 import-compat/ts-esm.ts
  18. +16 −6 jsconfig.json
  19. +556 −441 package-lock.json
  20. +20 −8 package.json
  21. +0 −91 packages/ARCHITECTURE.md
  22. 0 packages/README.md
  23. +62 −0 packages/core/CHANGELOG.md
  24. +12 −6 packages/core/package.json
  25. +2 −0 packages/core/rollup.config.mjs
  26. +13 −11 packages/core/src/CallHistory.js
  27. +178 −130 packages/core/src/FetchMock.js
  28. +125 −50 packages/core/src/Matchers.js
  29. +28 −21 packages/core/src/RequestUtils.js
  30. +35 −37 packages/core/src/Route.js
  31. +50 −28 packages/core/src/Router.js
  32. +9 −8 packages/core/src/__tests__/CallHistory.test.js
  33. +0 −2 packages/core/src/__tests__/FetchMock/instance-management.test.js
  34. +134 −0 packages/core/src/__tests__/FetchMock/mock-and-spy.test.js
  35. +98 −43 packages/core/src/__tests__/FetchMock/response-negotiation.test.js
  36. +0 −21 packages/core/src/__tests__/FetchMock/routing.test.js
  37. +2 −3 packages/core/src/__tests__/Matchers/body.test.js
  38. +96 −25 packages/core/src/__tests__/Matchers/{header.js → headers.test.js}
  39. +270 −59 packages/core/src/__tests__/Matchers/query-string.test.js
  40. +16 −15 packages/core/src/__tests__/Matchers/route-config-object.test.js
  41. +13 −0 packages/core/src/__tests__/Matchers/url.test.js
  42. +260 −122 packages/core/src/__tests__/router-integration.test.js
  43. +44 −0 packages/core/src/__tests__/spec-compliance.test.js
  44. +3 −0 packages/core/src/index.js
  45. +1 −0 packages/core/src/package.json
  46. +38 −0 packages/core/types/CallHistory.d.ts
  47. +107 −0 packages/core/types/FetchMock.d.ts
  48. +20 −35 packages/core/types/Matchers.d.ts
  49. +18 −11 packages/core/types/RequestUtils.d.ts
  50. +65 −138 packages/core/types/Route.d.ts
  51. +36 −218 packages/core/types/Router.d.ts
  52. +0 −3 packages/{wip/generated-types → core/types}/StatusTextMap.d.ts
  53. +4 −0 packages/core/types/index.d.ts
  54. +11 −0 packages/fetch-mock/CHANGELOG.md
  55. 0 mr → packages/fetch-mock/force
  56. +4 −1 packages/fetch-mock/package.json
  57. +2 −0 packages/fetch-mock/rollup.config.mjs
  58. 0 packages/fetch-mock/test-release
  59. +4 −2 packages/fetch-mock/test/framework-compat/jest.spec.js
  60. +0 −214 packages/standalone/fallbackToNetwork.test.js
  61. +0 −69 packages/standalone/fragments.js
  62. +0 −136 packages/standalone/global-fetch.test.js
  63. +0 −198 packages/standalone/set-up-and-tear-down.test.js
  64. +0 −89 packages/standalone/spy.test.js
  65. +0 −30 packages/standalone/types.ts
  66. +0 −11 packages/wip/generated-types/CallHistory.d.ts
  67. +0 −17 packages/wip/generated-types/FetchHandler.d.ts
  68. +0 −2 packages/wip/generated-types/FetchMockWrapper.d.ts
  69. +0 −16 packages/wip/generated-types/Matchers.d.ts
  70. +0 −27 packages/wip/generated-types/RequestUtils.d.ts
  71. +0 −2 packages/wip/generated-types/ResponseBuilder.d.ts
  72. +0 −44 packages/wip/generated-types/Route.d.ts
  73. +0 −3 packages/wip/generated-types/Router.d.ts
  74. +0 −1 packages/wip/generated-types/__tests__/CallHistory.test.d.ts
  75. +0 −1 packages/wip/generated-types/__tests__/FetchHandler.test.d.ts
  76. +0 −1 packages/wip/generated-types/__tests__/FetchMockWrapper.test.d.ts
  77. +0 −1 packages/wip/generated-types/__tests__/Matchers.test.d.ts
  78. +0 −1 packages/wip/generated-types/__tests__/ResponseBuilder.test.d.ts
  79. +0 −1 packages/wip/generated-types/__tests__/Router/Router.test.d.ts
  80. +0 −1 packages/wip/generated-types/__tests__/Router/body-matching.test.d.ts
  81. +0 −1 packages/wip/generated-types/__tests__/Router/edge-cases.test.d.ts
  82. +0 −1 packages/wip/generated-types/__tests__/Router/function-matching.test.d.ts
  83. +0 −1 packages/wip/generated-types/__tests__/Router/header-matching.test.d.ts
  84. +0 −1 packages/wip/generated-types/__tests__/Router/matchPartialBody.test.d.ts
  85. +0 −1 packages/wip/generated-types/__tests__/Router/matcher-object.test.d.ts
  86. +0 −1 packages/wip/generated-types/__tests__/Router/method-matching.test.d.ts
  87. +0 −1 packages/wip/generated-types/__tests__/Router/multiple-routes.test.d.ts
  88. +0 −1 packages/wip/generated-types/__tests__/Router/naming-routes.test.d.ts
  89. +0 −1 packages/wip/generated-types/__tests__/Router/path-parameter-matching.test.d.ts
  90. +0 −1 packages/wip/generated-types/__tests__/Router/query-string-matching.test.d.ts
  91. +0 −1 packages/wip/generated-types/__tests__/Router/sticky-routes.test.d.ts
  92. +0 −1 packages/wip/generated-types/__tests__/Router/unmatched-calls.test.d.ts
  93. +0 −1 packages/wip/generated-types/__tests__/Router/url-matching.test.d.ts
  94. +0 −159 packages/wip/old-types/CallHistory.d.ts
  95. +0 −84 packages/wip/old-types/FetchMockWrapper.d.ts
  96. +0 −27 packages/wip/old-types/RequestUtils.d.ts
  97. +0 −54 packages/wip/old-types/ResponseBuilder.d.ts
  98. +0 −7 packages/wip/old-types/StatusTextMap.d.ts
  99. +0 −16 packages/wip/old-types/index.d.ts
  100. +4 −2 release-please-config.json
  101. +0 −35 rollup.config.js
  102. +18 −0 shared-rollup.config.js
23 changes: 19 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -57,18 +57,22 @@ jobs:
steps:
- *workspace
- run: npm run lint:ci
- run: npm run prettier:ci

typelint:
<<: *nodelts
steps:
- *workspace
- run: npm run types:lint
- run: npm run types:check --noEmit=true

test:
<<: *nodelts
steps:
- *workspace
- run: npm run test:ci
- store_test_results:
path: test-results

nodefetch3:
<<: *nodelts
@@ -89,6 +93,14 @@ jobs:
- *workspace
- run: npm run build
- run: npm run test:jest
import-compat:
<<: *nodelts
steps:
- *workspace
- run: npm run compat:ts:cjs -w import-compat
- run: npm run compat:js:cjs -w import-compat
- run: npm run compat:ts:esm -w import-compat
- run: npm run compat:js:esm -w import-compat
# chrome:
# <<: *browsers
# steps:
@@ -131,12 +143,10 @@ workflows:
<<: *triggerable-by-tag
requires:
- checkout_code
# could be parallel with build, lint, and unit but it's a slow job
# And circlecifree tier only has 3 concurrent jobs, so overall faster
# to defer
- typelint:
<<: *triggerable-by-tag
<<: *run-after-first-jobs
requires:
- checkout_code
- nodefetch3:
<<: *triggerable-by-tag
<<: *run-after-first-jobs
@@ -146,6 +156,10 @@ workflows:
- jest:
<<: *triggerable-by-tag
<<: *run-after-first-jobs
- import-compat:
<<: *triggerable-by-tag
requires:
- build
# - chrome:
# <<: *triggerable-by-tag
# <<: *run-after-first-jobs
@@ -158,6 +172,7 @@ workflows:
# - chrome
# - firefox
- build
# - import-compat
- typelint
- commonjs
- jest
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/node_modules/
node_modules/

# tooling artefacts
/docs/.sass-cache/
@@ -13,3 +13,7 @@ coverage/
# built files
/docs/fetch-mock/dist/
/packages/**/dist

import-compat/*.js
import-compat/*.mjs
test-results
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npm run lint
npx lint-staged
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGELOG.md
4 changes: 2 additions & 2 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"packages/core": "0.3.1",
"packages/fetch-mock": "10.1.1"
"packages/core": "0.4.8",
"packages/fetch-mock": "11.0.0"
}
8 changes: 8 additions & 0 deletions docs/blog/2024-07-21-introducing-core.md
Original file line number Diff line number Diff line change
@@ -53,6 +53,14 @@ fetchMock.mock('http://my.site', 200);

which keeps fetch-mock's methods much further away from any other library's workings.

## .getAny(), .postAny(), .putAny(), .deleteAny(), .headAny(), .patchAny(), .getAnyOnce(), .postAnyOnce(), .putAnyOnce(), .deleteAnyOnce(), .headAnyOnce(), .patchAnyOnce()

While `.getOnce()` etc feel very useful, the `any` and `anyOnce` variants added a lot of repetition to the code and types, and don't actually add much value.

`.___AnyOnce(response, options)`

Creates a route that responds to any single request using a particular http method.

### Gone, but back soon

The following features will return in other libraries that wrap @fetch-mock/core for different environments.
26 changes: 26 additions & 0 deletions docs/blog/2024-07-24-esm-and-commonjs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: Publishing packages as ESM and commonjs
slug: esm-and-commonjs
authors:
- name: Rhys Evans
title: fetch-mock maintainer
url: https://www.wheresrhys.co.uk
hide_table_of_contents: false
---

Publishing a package that is compatible with all the following is not straightforward

1. A commonjs javascript project
2. A ESM javascript project
3. A commonjs typescript project
4. A ESM typescript project

I previously thought I'd cracked it by adding `"type": "module"` to the package.json but including a `{"type": "commonjs"}` package.json to the subdirectory that contained my commonjs built files.

However [this issue](https://github.com/wheresrhys/fetch-mock/issues/726) indicated that use case 3 was not supported. [This article](https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html) suggested that the best solution was to build a .mjs file for ESM, a .cjs file for CJS, and leave the top level package.json without a `"type": "module"` declaration.

I'm not a big fan of this as it makes it harder to fork the library or test a branch because every way of requiring it entails a build step, which is typically not carried out when requireing directly from a branch.

So after mulling things over I came up with a simple solution: remove the `"type": "module"` declaration from the top level package.json and instead create a `{"type": "module"}` package.json in my srcdirectory.

I thought I'd share as it's not obvious this would work - I did a fair bit of manual testing to prove it - but it's an elegant and low-build approach I've not seen publicised elsewhere.
17 changes: 9 additions & 8 deletions docs/docs/@fetch-mock/core/CallHistory.md
Original file line number Diff line number Diff line change
@@ -10,14 +10,15 @@ sidebar_position: 4

Calls are recorded, and returned, in a standard format with the following properties:

- `[string|Request,Object]` - the original arguments passed in to `fetch`
- `{string} url` - The url being fetched
- `{NormalizedRequestOptions} options` - The options passed in to the fetch (may be derived from a `Request` if one was used)
- `{Request} [request]` - The `Request` passed to fetch, if one was used
- `{Route} [route]` - The route used to handle the request
- `{Response} [response]` - The `Response` returned to the user
- `{Object.<string,string>}` - Any express parameters extracted from the `url`
- `{Promise<any>[]} pendingPromises` - An internal structure used by the `.flush()` method documented below
- **arguments** `[string|Request,Object]` - the original arguments passed in to `fetch`
- **url** `{string}` - The url being fetched
- **options** `{NormalizedRequestOptions}` - The options passed in to the fetch (may be derived from a `Request` if one was used)
- **request** `{Request}` - The `Request` passed to fetch, if one was used
- **route** `{Route}` - The route used to handle the request
- **response** `{Response}` - The `Response` returned to the user
- **expressParams** `{Object.<string,string>}` - Any express parameters extracted from the `url`
- **queryParams** `{URLSearchParams}` - Any query parameters extracted from the `url`
- **pendingPromises** `{Promise<any>[]} ` - An internal structure used by the `.flush()` method documented below

## Filtering

18 changes: 18 additions & 0 deletions docs/docs/@fetch-mock/core/index.md
Original file line number Diff line number Diff line change
@@ -12,3 +12,21 @@ This library implements three main features
3. Some low level APIs for accessing the call history of `fetchHandler` (these are not intended for direct use by the developer, but expose enough information for other libraries, such as `@fetch-mock/jest`, to provide more user friendly APIs built on top of this low level functionality).

`@fetch-mock/core` is not intended for direct use in tests. It **DOES NOT** actually replace your `fetch` implementation with `fetchHandler`; this is left to wrapper libraries such as `@fetch-mock/jest`. This is because different testing frameworks have different opinions about this behaviour, and this core library deliberately avoids making decisions likely to clash with other tools in your testing toolchain, so that the `fetchHandler` implementation is more portable.

```js
import fetchMock from '@fetch-mock/core';
describe('myModule', () => {
beforeEach(() => fetchMock.mockGlobal())

it('gets user data from the api endpoint', async () => {
fetchMock.route({
express: '/api/users/:user'
expressParams: {user: 'kenneth'}
}, {userData: {}}, 'userDataFetch')
await myModule.initialiseUserPage({user: 'kenneth'})
expect(fetchMock.called('userDataFetch'))

})
})

```
29 changes: 29 additions & 0 deletions docs/docs/@fetch-mock/core/mocking-and-spying.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
sidebar_position: 3
---

# Mocking and spying

These methods allow mocking or spying on the `fetch` implementation used by your application.

Note that these methods are only implemented in `@fetch-mock/core` and are not avilable when using `@fetch-mock/jest`, `@fetch-mock/vitest` etc.... Those libraries provide ways to mock `fetch` that are more idiomatic to their own ecosystem.

## When using global fetch in your application

### mockGlobal()

Replaces `globalThis.fetch` with `fm.fetchHandler`

### unmockGlobal()

Restores `globalThis.fetch` to its original state

### spy(matcher, name)

Falls back to the `fetch` implementation set in `fetchMock.config.fetch` for a specific route (which can be named).

When no arguments are provided it will fallback to the native fetch implementation for all requests, similar to `.catch()`

### spyGlobal()

Equivalent to calling `.mockGlobal()` followed by `.spy()`
14 changes: 1 addition & 13 deletions docs/docs/@fetch-mock/core/more-routing-methods.md
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ sidebar_label: More routing methods

# More routing methods

These methods allow defining routes for common use cases while avoiding writing hard to read configuration objects. They all return the fetchMock instance, and are therefor chainable. Unless noted otherwise, each of the methods below have the same signature as `.route()`.
These methods allow defining routes for common use cases while avoiding writing hard to read configuration objects. They all return the fetchMock instance, and are therefor chainable. Unless noted otherwise, each of the methods below have the same signature as `.route()`.

## .catch()

@@ -61,18 +61,6 @@ fetchMock.purge = function (matcher, response, options) {

Creates a route that only responds to a single request using a particular http method

## .getAny(), .postAny(), .putAny(), .deleteAny(), .headAny(), .patchAny()

`.___Any(response, options)`

Creates a route that responds to any requests using a particular http method.

## .getAnyOnce(), .postAnyOnce(), .putAnyOnce(), .deleteAnyOnce(), .headAnyOnce(), .patchAnyOnce()

`.___AnyOnce(response, options)`

Creates a route that responds to any single request using a particular http method.

## .addMatcher(options)

Allows adding your own, reusable custom matchers to fetch-mock, for example a matcher for interacting with GraphQL queries, or an `isAuthorized` matcher that encapsulates the exact authorization conditions for the API you are mocking, and only requires a `true` or `false` to be input
4 changes: 4 additions & 0 deletions docs/docs/@fetch-mock/core/resetting.md
Original file line number Diff line number Diff line change
@@ -26,6 +26,10 @@ A boolean indicating whether or not to remove the fallback route (added using `.

Clears all data recorded for `fetch`'s calls.

## unmockGlobal()

Restores global `fetch` to its original state if `.mockGlobal()` or `.spyGlobal()` have been used .

## .createInstance()

Can be used to create a standalone instance of fetch mock that is completely independent of other instances.
26 changes: 23 additions & 3 deletions docs/docs/@fetch-mock/core/route/matcher.md
Original file line number Diff line number Diff line change
@@ -71,17 +71,31 @@ Match a url that satisfies an [express style path](https://www.npmjs.com/package

When the `express:` keyword is used in a string matcher, it can be combined with the `{params: ...}` matcher to match only requests whose express parameters evaluate to certain values. e.g.

```
```js
{
express: "/:section/user/:user",
url: "express:/:section/user/:user",
params: {"section": "feed", "user": "geoff"}
}
```

The values of express parameters are made available in the `expressParams` property when
The values of express parameters are made available in the `expressParams` property when

- [Inspecting call history](/fetch-mock/docs/@fetch-mock/core/CallHistory#calllog-schema)
- [Using a function to construct a response](/fetch-mock/docs/@fetch-mock/core/route/response#function)

### Multiple url matchers

All of the above (with the exception of the full url matcher) can be combined in an object in order to match multiple patterns at once e.g.

```js
{
url: {
begin: 'https',
path: '/could/be/any/host'
}
}
```

## Other matching criteria

### method
@@ -96,6 +110,12 @@ Match only requests using this http method. Not case-sensitive, e.g. `{method: "

Match only requests that have these headers set, e.g. `{headers: {"Accepts": "text/html"}}`

#### missingHeaders

`{String[]}`

Matches any requests where **all** of a list of header names are missing on a request e.g. `{missingHeaders: ["Authorization"]}`.

### query

`{Object}`
6 changes: 4 additions & 2 deletions docs/docs/fetch-mock/Usage/versions.md
Original file line number Diff line number Diff line change
@@ -4,13 +4,15 @@ sidebar_position: 5

# Versions

### Version 10
### Version 10/11

This has 2 major differences from previous versions
These have 2 major differences from previous versions

1. It is written using ES modules
2. It uses native fetch in node.js

Version 11 is identical to version 10, with the exception that it changes the commonjs to use `exports.default = fetchMock` instead of `exports=fetchMock`.

If you experience any compatibility issues upgrading from version 9, please either

- try the approaches iom the troubleshooting section of these docs
10 changes: 10 additions & 0 deletions import-compat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "fetch-mock-compat-tests",
"version": "1.0.0",
"scripts": {
"compat:ts:esm": "tsc ts-esm.ts --target esnext --moduleResolution nodenext --module nodenext && node ts-esm.js",
"compat:ts:cjs": "tsc ts-cjs.ts --target esnext --moduleResolution nodenext --module nodenext && node ts-cjs.js",
"compat:js:esm": "cp ts-esm.ts js-esm.mjs && node js-esm.mjs",
"compat:js:cjs": "cp ts-cjs.ts js-cjs.js && node js-cjs.js"
}
}
7 changes: 7 additions & 0 deletions import-compat/ts-cjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const {default: fetchMockCore, FetchMock} = require("@fetch-mock/core");
fetchMockCore.route("http://example.com", 200);

new FetchMock({})

const fetchMock = require("fetch-mock").default;
fetchMock.mock("http://example.com", 200);
7 changes: 7 additions & 0 deletions import-compat/ts-esm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import fetchMockCore, {FetchMock} from "@fetch-mock/core";
fetchMockCore.route("http://example.com", 200);

new FetchMock({})

import fetchMock from "fetch-mock";
fetchMock.mock("http://example.com", 200);
22 changes: 16 additions & 6 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -5,22 +5,32 @@
"dom",
"dom.iterable"
],
"moduleResolution": "nodenext",
"module": "NodeNext",
"allowJs": true,
"checkJs": true,
"strict": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"types": [ ],
"noEmit": true,
"types": [
],
"downlevelIteration": true,
"forceConsistentCasingInFileNames": true
"forceConsistentCasingInFileNames": true,
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "packages/core/types",
"skipLibCheck": true,
"noEmit": false,
"target": "es2021",
"removeComments": true
},
"include": [
"packages/core/src/*.js",
"./packages/core/src/*.js"
],
"exclude": [
"node_modules"
"node_modules",
"packages/**/src/__tests__"
]
}
}
Loading