Created
July 13, 2014 21:22
-
-
Save Furzel/829dc2ef818799857aff to your computer and use it in GitHub Desktop.
How to add a custom assertion to should.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.