@bonniernews/httptest
Advanced tools
Comparing version 1.1.0 to 2.0.0
@@ -11,2 +11,6 @@ Changelog | ||
## [2.0.0] - 2022-08-23 | ||
### Changed | ||
- Parse and return response body as JSON if content type matches application/json | ||
## [1.1.0] - 2022-04-13 | ||
@@ -13,0 +17,0 @@ ### Added |
@@ -8,2 +8,4 @@ "use strict"; | ||
const jsonContentTypePattern = /application\/json/i; | ||
module.exports = HttpTest; | ||
@@ -77,3 +79,3 @@ | ||
if (value) this._options.responseType = "json"; | ||
else delete this._options.responseType; | ||
else this._options.responseType = "text"; | ||
return this; | ||
@@ -124,2 +126,5 @@ } | ||
const res = await makeRequest(); | ||
if (!("responseType" in this._options) && jsonContentTypePattern.test(res.headers["content-type"])) { | ||
res.body = JSON.parse(res.text); | ||
} | ||
for (const test of this._asserts.splice(0)) { | ||
@@ -126,0 +131,0 @@ test.fn.call(this, res, ...test.args); |
{ | ||
"name": "@bonniernews/httptest", | ||
"version": "1.1.0", | ||
"description": "", | ||
"version": "2.0.0", | ||
"description": "HTTP testing library", | ||
"main": "index.js", | ||
@@ -30,13 +30,13 @@ "scripts": { | ||
"cookiejar": "^2.1.3", | ||
"got": "^11.8.3" | ||
"got": "^11.8.5" | ||
}, | ||
"devDependencies": { | ||
"body-parser": "^1.19.2", | ||
"c8": "^7.11.0", | ||
"body-parser": "^1.20.0", | ||
"c8": "^7.12.0", | ||
"chai": "^4.3.6", | ||
"eslint": "^8.10.0", | ||
"eslint-config-exp": "^0.2.0", | ||
"express": "^4.17.3", | ||
"mocha": "^9.2.1", | ||
"nock": "^13.2.4" | ||
"eslint": "^8.22.0", | ||
"eslint-config-exp": "^0.4.0", | ||
"express": "^4.18.1", | ||
"mocha": "^10.0.0", | ||
"nock": "^13.2.9" | ||
}, | ||
@@ -43,0 +43,0 @@ "files": [ |
@@ -80,2 +80,10 @@ HTTP Test | ||
}); | ||
it("response content-type json returns body as JSON", async () => { | ||
await HttpTest(app) | ||
.post("/", {}) | ||
.expect(200) | ||
.expect("content-type", "application/json; charset=utf-8") | ||
.expect({ foo: "bar" }); | ||
}); | ||
``` |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
12390
260
89
1
Updatedgot@^11.8.5