@efebia/jest-match-response 0.0.1 → 0.0.2
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/toMatchResponse.d.ts
CHANGED
package/lib/toMatchResponse.js
CHANGED
|
@@ -3,17 +3,20 @@ 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
|
|
7
|
-
throw new Error('toMatchResponse: the received value
|
|
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 ?
|
|
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(
|
|
17
|
+
`Received Status Code: ${this.utils.printReceived(status)}\n` +
|
|
15
18
|
`Received Body: ${this.utils.printReceived(jsonResponse)}`);
|
|
16
|
-
return { actual:
|
|
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);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@efebia/jest-match-response",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
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",
|