mirror of
https://github.com/chaijs/chai
synced 2024-11-15 08:17:14 +00:00
56 lines
1.2 KiB
JavaScript
56 lines
1.2 KiB
JavaScript
/*!
|
|
* chai
|
|
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
|
|
* MIT Licensed
|
|
*/
|
|
|
|
module.exports = function (chai) {
|
|
var Assertion = chai.Assertion;
|
|
|
|
chai.should = function () {
|
|
// modify Object.prototype to have `should`
|
|
Object.defineProperty(Object.prototype, 'should', {
|
|
set: function(){},
|
|
get: function(){
|
|
if (this instanceof String || this instanceof Number) {
|
|
return new Assertion(this.constructor(this));
|
|
} else if (this instanceof Boolean) {
|
|
return new Assertion(this == true);
|
|
}
|
|
return new Assertion(this);
|
|
},
|
|
configurable: true
|
|
});
|
|
|
|
var should = {};
|
|
|
|
should.equal = function (val1, val2) {
|
|
new Assertion(val1).to.equal(val2);
|
|
};
|
|
|
|
should.throw = function (fn, err) {
|
|
new Assertion(fn).to.throw(err);
|
|
};
|
|
|
|
should.exist = function (val) {
|
|
new Assertion(val).to.exist;
|
|
}
|
|
|
|
// negation
|
|
should.not = {}
|
|
|
|
should.not.equal = function (val1, val2) {
|
|
new Assertion(val1).to.not.equal(val2);
|
|
};
|
|
|
|
should.not.throw = function (fn, err) {
|
|
new Assertion(fn).to.not.throw(err);
|
|
};
|
|
|
|
should.not.exist = function (val) {
|
|
new Assertion(val).to.not.exist;
|
|
}
|
|
|
|
return should;
|
|
};
|
|
};
|