Skip to content

Commit

Permalink
cleaner should interface export.
Browse files Browse the repository at this point in the history
- also aliased `chai.Should()` as the original would be overwritten after the first call (helps when using watch mode for test runners)
  • Loading branch information
logicalparadox committed May 4, 2012
1 parent 755a369 commit 1082fc6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
25 changes: 14 additions & 11 deletions lib/interface/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
module.exports = function (chai, util) {
var Assertion = chai.Assertion;

chai.should = function () {
function loadShould () {
// 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);
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);
}
return new Assertion(this);
},
configurable: true
, configurable: true
});

var should = {};
Expand Down Expand Up @@ -56,4 +56,7 @@ module.exports = function (chai, util) {

return should;
};

chai.should = loadShould;
chai.Should = loadShould;
};
4 changes: 2 additions & 2 deletions test/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ if (!chai) {
var chai = require('..');
}

var should = chai.should();
var should = chai.Should();

function err(fn, msg) {
try {
fn();
throw new chai.AssertionError({ message: 'Expected an error' });
} catch (err) {
should.equal(err.message, msg);
chai.expect(err.message).to.equal(msg);
}
}

Expand Down

0 comments on commit 1082fc6

Please sign in to comment.