Skip to content

Commit

Permalink
Closes #53 - 'a' and 'an' is now similar, 'have.type' replaces 'be.a'.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Falkenberg committed Sep 13, 2013
1 parent 3513d65 commit d9a8098
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
16 changes: 13 additions & 3 deletions lib/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ Assertion.prototype = {
return this;
},

/**
* Dummy getter.
*
* @api public
*/

get a() {
return this;
},

/**
* Dummy getter.
*
Expand Down Expand Up @@ -359,11 +369,11 @@ Assertion.prototype = {
* @api public
*/

a: function(type, desc){
type: function(type, desc){
this.assert(
type == typeof this.obj
, function(){ return 'expected ' + this.inspect + ' to be a ' + type + (desc ? " | " + desc : "") }
, function(){ return 'expected ' + this.inspect + ' not to be a ' + type + (desc ? " | " + desc : "") })
, function(){ return 'expected ' + this.inspect + ' to have type ' + type + (desc ? " | " + desc : "") }
, function(){ return 'expected ' + this.inspect + ' not to have type ' + type + (desc ? " | " + desc : "") })
return this;
},

Expand Down
22 changes: 11 additions & 11 deletions test/should.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,25 @@ module.exports = {
},

'test typeof': function(){
'test'.should.be.a('string');
'test'.should.have.type('string');

err(function(){
'test'.should.not.be.a('string');
}, "expected 'test' not to be a string");
'test'.should.not.have.type('string');
}, "expected 'test' not to have type string");

err(function(){
'test'.should.not.be.a('string', 'foo');
}, "expected 'test' not to be a string | foo");
'test'.should.not.have.type('string', 'foo');
}, "expected 'test' not to have type string | foo");

(5).should.be.a('number');
(5).should.have.type('number');

err(function(){
(5).should.not.be.a('number');
}, "expected 5 not to be a number");
(5).should.not.have.type('number');
}, "expected 5 not to have type number");

err(function(){
(5).should.not.be.a('number', 'foo');
}, "expected 5 not to be a number | foo");
(5).should.not.have.type('number', 'foo');
}, "expected 5 not to have type number | foo");
},

'test instanceof': function(){
Expand Down Expand Up @@ -616,7 +616,7 @@ module.exports = {
user.should.have.property('pets').with.lengthOf(5);
}, "expected [ 'tobi', 'loki', 'jane', 'bandit' ] to have a length of 5 but got 4");

user.should.be.a('object').and.have.property('name', 'tj');
user.should.be.instanceOf(Object).and.have.property('name', 'tj');
},

'test throw()': function(){
Expand Down

0 comments on commit d9a8098

Please sign in to comment.