Skip to content

Commit

Permalink
Merge pull request #219 from austince/fix/inherited-properties
Browse files Browse the repository at this point in the history
fix(inherited properties): Allow for status / statusCode to exist on the prototype
  • Loading branch information
JamesMessinger authored Aug 1, 2018
2 parents 1af976d + 5de4b03 commit d515691
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
node_modules
coverage/

# IDEs
.idea
.vscode
11 changes: 10 additions & 1 deletion lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,16 @@ module.exports = function (chai, _) {
*/

Assertion.addMethod('status', function (code) {
new Assertion(this._obj).to.have.any.keys('status', 'statusCode');
var hasStatus = Boolean('status' in this._obj || 'statusCode' in this._obj);
new Assertion(hasStatus).assert(
hasStatus
, "expected #{act} to have keys 'status', or 'statusCode'"
, null // never negated
, hasStatus // expected
, this._obj // actual
, false // no diff
);

var status = this._obj.status || this._obj.statusCode;

this.assert(
Expand Down
7 changes: 7 additions & 0 deletions test/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ describe('assertions', function () {
res.should.to.have.status(200);
});

it('#status property "status" should work with inheritance', function () {
function TestError() {};
TestError.prototype.status = 404;
var testError = new TestError();
testError.should.have.status(404);
});

it('#ip', function () {
'127.0.0.1'.should.be.an.ip;
'2001:0db8:85a3:0000:0000:8a2e:0370:7334'.should.be.an.ip;
Expand Down

0 comments on commit d515691

Please sign in to comment.