@efebia/jest-match-response 0.0.5 → 0.0.6
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 +0 -7
- package/lib/index.js +1 -10
- package/lib/toMatchResponse.js +3 -3
- package/package.json +1 -1
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.
|
|
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;
|
package/lib/toMatchResponse.js
CHANGED
|
@@ -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 =
|
|
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 =
|
|
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' +
|