Skip to content

Commit

Permalink
fix: Allow checking properties of prototype and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
austince committed Jul 31, 2018
1 parent 1af976d commit 5de4b03
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
@@ -1,2 +1,6 @@
node_modules
coverage/

# IDEs
.idea
.vscode
11 changes: 10 additions & 1 deletion lib/http.js
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
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 5de4b03

Please sign in to comment.