supertest-fetch
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -172,3 +172,3 @@ "use strict"; | ||
* | ||
* @param body - The body to verify. This can be either a string, a regex, | ||
* @param expectedBody - The body to verify. This can be either a string, a regex, | ||
* or a JSON object. If an object, this will treat the response like JSON | ||
@@ -178,20 +178,20 @@ * data. Passing `null` or `undefined` to expectBody will verify that the | ||
*/ | ||
Test.prototype.expectBody = function (body) { | ||
Test.prototype.expectBody = function (expectedBody) { | ||
var _this = this; | ||
this._result = this._result.then(function (response) { return __awaiter(_this, void 0, void 0, function () { | ||
var _a, _b, regex, _c, _d, _e, _f, _g; | ||
return __generator(this, function (_h) { | ||
switch (_h.label) { | ||
var _a, _b, regex, _c, _d, _e, textBody, jsonBody; | ||
return __generator(this, function (_f) { | ||
switch (_f.label) { | ||
case 0: | ||
if (!(typeof body === 'string')) return [3 /*break*/, 2]; | ||
if (!(typeof expectedBody === 'string')) return [3 /*break*/, 2]; | ||
_b = (_a = assert_1.default).strictEqual; | ||
return [4 /*yield*/, response.text()]; | ||
case 1: | ||
_b.apply(_a, [_h.sent(), | ||
body, | ||
_b.apply(_a, [_f.sent(), | ||
expectedBody, | ||
this._should("have expected body")]); | ||
return [3 /*break*/, 7]; | ||
case 2: | ||
if (!(body instanceof RegExp)) return [3 /*break*/, 4]; | ||
regex = body; | ||
if (!(expectedBody instanceof RegExp)) return [3 /*break*/, 4]; | ||
regex = expectedBody; | ||
_c = assert_1.default; | ||
@@ -201,13 +201,23 @@ _e = (_d = regex).exec; | ||
case 3: | ||
_c.apply(void 0, [!!_e.apply(_d, [_h.sent()]), | ||
_c.apply(void 0, [!!_e.apply(_d, [_f.sent()]), | ||
this._should("have a body with a value that matches " + regex)]); | ||
return [3 /*break*/, 7]; | ||
case 4: | ||
if (!(body && typeof body === 'object')) return [3 /*break*/, 6]; | ||
_g = (_f = assert_1.default).deepEqual; | ||
return [4 /*yield*/, response.json()]; | ||
if (!(expectedBody && typeof expectedBody === 'object')) return [3 /*break*/, 6]; | ||
return [4 /*yield*/, response.text()]; | ||
case 5: | ||
_g.apply(_f, [_h.sent(), | ||
body, | ||
this._should("have expected JSON body")]); | ||
textBody = _f.sent(); | ||
jsonBody = void 0; | ||
try { | ||
jsonBody = JSON.parse(textBody); | ||
} | ||
catch (err) { | ||
throw new assert_1.default.AssertionError({ | ||
message: this._should("have JSON body but body could not be parsed: " + err.message), | ||
expected: expectedBody, | ||
actual: textBody, | ||
operator: 'deepStrictEqual' | ||
}); | ||
} | ||
assert_1.default.deepStrictEqual(jsonBody, expectedBody, this._should("have expected JSON body")); | ||
return [3 /*break*/, 7]; | ||
@@ -218,3 +228,3 @@ case 6: | ||
assert_1.default(!response.headers.has('transfer-encoding'), this._should("not have a body, but has a transfer-encoding header")); | ||
_h.label = 7; | ||
_f.label = 7; | ||
case 7: return [2 /*return*/, response]; | ||
@@ -221,0 +231,0 @@ } |
{ | ||
"name": "supertest-fetch", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Supertest with WHATWG fetch like interface.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -42,3 +42,3 @@ import * as fetch from 'node-fetch'; | ||
* | ||
* @param body - The body to verify. This can be either a string, a regex, | ||
* @param expectedBody - The body to verify. This can be either a string, a regex, | ||
* or a JSON object. If an object, this will treat the response like JSON | ||
@@ -48,3 +48,3 @@ * data. Passing `null` or `undefined` to expectBody will verify that the | ||
*/ | ||
expectBody(body: any): this; | ||
expectBody(expectedBody: any): this; | ||
/** | ||
@@ -51,0 +51,0 @@ * Verifies a header exists and has the specified value. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36013
488