@bonniernews/httptest
Advanced tools
Comparing version 0.0.2 to 1.0.0
25
index.js
@@ -97,4 +97,17 @@ "use strict"; | ||
case "string": | ||
this._asserts.push({ fn: assertHeader, args }); | ||
if (args.length === 1) { | ||
this._asserts.push({ fn: assertBody, args }); | ||
} else { | ||
this._asserts.push({ fn: assertHeader, args }); | ||
} | ||
break; | ||
case "object": | ||
this._asserts.push({ fn: assertBody, args }); | ||
break; | ||
default: { | ||
if (args.length === 1) { | ||
this._asserts.push({ fn: assertBody, args }); | ||
} | ||
break; | ||
} | ||
} | ||
@@ -131,2 +144,12 @@ return this; | ||
function assertBody(res, expected) { | ||
if (expected instanceof RegExp) { | ||
return assert.match(res.text, expected, "unexpected body"); | ||
} else if (expected !== null && typeof expected === "object") { | ||
return assert.deepStrictEqual(res.body, expected, "unexpected body"); | ||
} | ||
assert.equal(res.text, expected, "unexpected body"); | ||
} | ||
function HttpTest(initiator, options) { | ||
@@ -133,0 +156,0 @@ if (!(this instanceof HttpTest)) return new HttpTest(initiator, options); |
{ | ||
"name": "@bonniernews/httptest", | ||
"version": "0.0.2", | ||
"version": "1.0.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -37,3 +37,3 @@ HTTP Test | ||
- `redirects(maxRedirects)`: set number of max redirects, defaults to 0 | ||
- `expect(arg[, arg])`: expect statusCode or header with value | ||
- `expect(arg[, arg])`: expect statusCode, header with value, and body | ||
@@ -60,4 +60,6 @@ ## `HttpTest.agent(origin, options)` | ||
.post("/", {}) | ||
.json() | ||
.expect(200) | ||
.expect("content-type", "application/json; charset=utf-8"); | ||
.expect("content-type", "application/json; charset=utf-8") | ||
.expect({ foo: "bar" }); | ||
}); | ||
@@ -64,0 +66,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
11480
5
253
1
72