Skip to content

Instantly share code, notes, and snippets.

@Furzel
Created July 13, 2014 21:22
Show Gist options
  • Save Furzel/829dc2ef818799857aff to your computer and use it in GitHub Desktop.
Save Furzel/829dc2ef818799857aff to your computer and use it in GitHub Desktop.
How to add a custom assertion to should.js
var should = require('should');
should.use(function (should, Assertion) {
Assertion.add('myEql', function (value, description) {
this.params = { operator: 'to be' + should.format(expectedTraces), message: description};
this.assert(value === this.obj);
});
});
describe('test', function () {
it('should work', function () {
var a = 42;
a.should.be.myEql(42);
});
});
@Furzel
Copy link
Author

Furzel commented Jul 13, 2014

in the assertion function this.obj is your original value ( var a in our case ) and value is the parameter of myEql(). The only thing left is to call this.assert for wathever condition you can need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment