@efebia/jest-match-response 0.0.5 → 0.0.7

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.
package/lib/index.d.ts CHANGED
@@ -1,9 +1,2 @@
1
1
  export { buildToMatchJson, type Options } from "./toMatchJson";
2
2
  export { toMatchResponse } from "./toMatchResponse";
3
- export declare const matchResponseAndReturn: (response: {
4
- json: () => any | Promise<any>;
5
- } & ({
6
- status: number;
7
- } | {
8
- statusCode: number;
9
- }), statusCode: number, model: any) => Promise<any>;
package/lib/index.js CHANGED
@@ -1,16 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.matchResponseAndReturn = exports.toMatchResponse = exports.buildToMatchJson = void 0;
3
+ exports.toMatchResponse = exports.buildToMatchJson = void 0;
4
4
  var toMatchJson_1 = require("./toMatchJson");
5
5
  Object.defineProperty(exports, "buildToMatchJson", { enumerable: true, get: function () { return toMatchJson_1.buildToMatchJson; } });
6
6
  var toMatchResponse_1 = require("./toMatchResponse");
7
7
  Object.defineProperty(exports, "toMatchResponse", { enumerable: true, get: function () { return toMatchResponse_1.toMatchResponse; } });
8
- const matchResponseAndReturn = async (response, statusCode, model) => {
9
- const jsonValue = await response.json();
10
- expect({ ...response, json() {
11
- return jsonValue;
12
- } })
13
- .toMatchResponse(statusCode, model);
14
- return jsonValue;
15
- };
16
- exports.matchResponseAndReturn = matchResponseAndReturn;
@@ -17,7 +17,7 @@ const buildToMatchJson = (opts) => {
17
17
  `Expected JSON Schema: ${this.utils.printExpected(model)}\n` +
18
18
  `Received JSON: ${this.utils.printReceived(json)}` +
19
19
  showErrors
20
- ? `\nValidation errors: ${this.utils.printReceived(JSON.stringify(validate.errors))}`
20
+ ? `\nValidation errors: ${this.utils.printReceived(validate.errors)}`
21
21
  : "";
22
22
  return { actual: json, message, name: "toMatchJson", pass };
23
23
  };
@@ -2,15 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toMatchResponse = void 0;
4
4
  const globals_1 = require("@jest/globals");
5
- const toMatchResponse = async function (received, statusCode, model) {
5
+ const toMatchResponse = function (received, statusCode, model) {
6
6
  if (typeof received !== 'object' || !received)
7
7
  throw new Error('toMatchResponse: the received value needs to be of type object');
8
8
  if (!('json' in received && typeof received.json === 'function'))
9
- throw new Error('toMatchResponse: the received value needs to have a .json method');
9
+ throw new Error('toMatchResponse: the received value needs to have a .json synchronous method');
10
10
  if (!('status' in received || 'statusCode' in received))
11
11
  throw new Error('toMatchResponse: the received value needs to have a status or statusCode property');
12
12
  const status = ('status' in received ? received.status : received.statusCode);
13
- const jsonResponse = await received.json();
13
+ const jsonResponse = received.json();
14
14
  const statusCodePass = this.isNot ? status !== statusCode : status === statusCode;
15
15
  const message = () => (this.utils.matcherHint('toMatchResponse', undefined, undefined, { comment: 'Match response equality', isNot: this.isNot, promise: this.promise }) +
16
16
  '\n\n' +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@efebia/jest-match-response",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "license": "MIT",
5
5
  "devDependencies": {
6
6
  "@types/jest": "^29.2.5",