@efebia/jest-match-response 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,13 @@
1
1
  export declare const toMatchResponse: (received: any, statusCode: any, model: any) => Promise<void | {
2
- actual: number;
2
+ actual: any;
3
3
  message: () => string;
4
4
  name: string;
5
5
  pass: boolean;
6
+ } | {
7
+ pass: boolean;
8
+ actual?: undefined;
9
+ message?: undefined;
10
+ name?: undefined;
6
11
  }>;
7
12
  declare module "expect" {
8
13
  interface AsymmetricMatchers {
@@ -3,20 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toMatchResponse = void 0;
4
4
  const globals_1 = require("@jest/globals");
5
5
  const toMatchResponse = async function (received, statusCode, model) {
6
- if (!(received instanceof Response))
7
- throw new Error('toMatchResponse: the received value has to be a fetch Response object');
6
+ if (!(Object.hasOwn(received, 'json') && typeof received.json === 'function'))
7
+ throw new Error('toMatchResponse: the received value needs to have a .json method');
8
+ if (!(Object.hasOwn(received, 'status') || Object.hasOwn(received, 'statusCode')))
9
+ throw new Error('toMatchResponse: the received value needs to have a status or statusCode property');
10
+ const status = received.status || received.statusCode;
8
11
  const jsonResponse = await received.json();
9
- const statusCodePass = this.isNot ? received.status !== statusCode : received.status === statusCode;
12
+ const statusCodePass = this.isNot ? status !== statusCode : status === statusCode;
10
13
  if (!statusCodePass) {
11
14
  const message = () => (this.utils.matcherHint('toMatchResponse', undefined, undefined, { comment: 'Match response equality', isNot: this.isNot, promise: this.promise }) +
12
15
  '\n\n' +
13
16
  `Expected Status Code: ${this.utils.printExpected(statusCode)}\n` +
14
- `Received Status Code: ${this.utils.printReceived(received.status)}\n` +
17
+ `Received Status Code: ${this.utils.printReceived(status)}\n` +
15
18
  `Received Body: ${this.utils.printReceived(jsonResponse)}`);
16
- return { actual: received.status, message, name: 'toMatchResponse', pass: false };
19
+ return { actual: status, message, name: 'toMatchResponse', pass: false };
17
20
  }
18
21
  if (this.isNot)
19
22
  return (0, globals_1.expect)(jsonResponse).not.toMatchJson(model);
20
- return (0, globals_1.expect)(jsonResponse).toMatchJson(model);
23
+ (0, globals_1.expect)(jsonResponse).toMatchJson(model);
24
+ return { pass: true };
21
25
  };
22
26
  exports.toMatchResponse = toMatchResponse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@efebia/jest-match-response",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "license": "MIT",
5
5
  "devDependencies": {
6
6
  "@types/jest": "^29.2.5",
@@ -8,8 +8,7 @@
8
8
  "@types/node": "^18.11.18",
9
9
  "jest": "^29.3.1",
10
10
  "ts-jest": "^29.0.3",
11
- "typescript": "^4.9.4",
12
- "undici": "^5.24.0"
11
+ "typescript": "^4.9.4"
13
12
  },
14
13
  "dependencies": {
15
14
  "@jest/globals": ">=28.0.0",