Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unsupported is-subset-of package #871

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/Usage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

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

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/legacy-api/Usage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Configures behaviour when attempting to add a new route with the same name (or i

`{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.

### warnOnFallback

Expand Down
18 changes: 0 additions & 18 deletions package-lock.json

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

1 change: 0 additions & 1 deletion packages/fetch-mock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"@types/glob-to-regexp": "^0.4.4",
"dequal": "^2.0.3",
"glob-to-regexp": "^0.4.1",
"is-subset-of": "^3.1.10",
"regexparam": "^3.0.0"
},
"repository": {
Expand Down
21 changes: 20 additions & 1 deletion packages/fetch-mock/src/Matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { RouteConfig } from './Route.js';
import { CallLog } from './CallHistory.js';
import glob from 'glob-to-regexp';
import * as regexparam from 'regexparam';
import { isSubsetOf } from 'is-subset-of';
import { dequal as isEqual } from 'dequal';
import { normalizeHeaders, getPath, normalizeUrl } from './RequestUtils.js';

Expand Down Expand Up @@ -218,6 +217,26 @@ const getBodyMatcher: MatcherGenerator = (route) => {
};
};

const isSubsetOf = (
subset: Record<string, any>,
superset: Record<string, any>,
): boolean => {
return Object.entries(subset).every(([key, val]) => {
if (!(key in superset)) return false;

if (Array.isArray(val)) {
return Array.isArray(superset[key]) &&
val.every(item => superset[key].includes(item));
}

if (typeof val === 'object' && val !== null) {
return isSubsetOf(val, superset[key]);
}

return superset[key] === val;
});
};

const getFunctionMatcher: MatcherGenerator = ({ matcherFunction }) =>
matcherFunction;

Expand Down