Skip to content

Instantly share code, notes, and snippets.

@tonylukasavage
Created May 24, 2014 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonylukasavage/e737059af0414546f730 to your computer and use it in GitHub Desktop.
Save tonylukasavage/e737059af0414546f730 to your computer and use it in GitHub Desktop.
custom should.js assertion
// getter assertion
should.Assertion.add('CRAZY', function() {
this.params = {
operator: 'to be the string "CRAZY"',
expected: 'CRAZY',
showDiff: true
};
this.obj.should.equal('CRAZY');
}, true);
// function assertion
should.Assertion.add('HttpCode', function(code) {
this.params = {
operator: 'to be HTTP code',
expected: code,
showDiff: true
};
this.obj.statusCode.should.equal(code);
}, false);
var str = 'CRAZY';
var err = {
statusCode: 403
};
str.should.be.CRAZY; // pass
err.should.have.HttpCode(403); // pass
err.should.have.HttpCode(400); // fail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment