Skip to content

Commit

Permalink
Merge pull request #738 from wheresrhys/rhys/types3
Browse files Browse the repository at this point in the history
Rhys/types3
  • Loading branch information
wheresrhys authored Jul 24, 2024
2 parents 812f462 + 6c21822 commit 4e46676
Show file tree
Hide file tree
Showing 27 changed files with 470 additions and 688 deletions.
2 changes: 1 addition & 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/
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npm run lint
npm run lint && npm run types:lint && npm run types:check
8 changes: 8 additions & 0 deletions docs/blog/2024-07-21-introducing-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 0 additions & 12 deletions docs/docs/@fetch-mock/core/more-routing-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 16 additions & 6 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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__"
]
}
}
Empty file removed mr
Empty file.
95 changes: 19 additions & 76 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@
"prettier": "^3.1.1",
"rollup": "^4.9.1",
"ts-to-jsdoc": "^2.1.0",
"typescript": "^3.9.10",
"typescript": "^5.5.3",
"v8": "^0.1.0",
"vitest": "^1.1.0",
"@types/events": "^3.0.3",
"@types/globrex": "^0.1.4",
"webdriverio": "^8.27.0"
},
"volta": {
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"exports": "src/index.js",
"version": "0.3.1",
"main": "index.js",
"types": "types/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/CallHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class CallHistory {
this.callLogs.push(callLog);
}

/**
* @returns {void}
*/
clear() {
this.callLogs.forEach(({ route }) => route.reset());
this.callLogs = [];
Expand Down
Loading

0 comments on commit 4e46676

Please sign in to comment.