Merge pull request #27 from logicalparadox/type-fix

Typeof fixes
This commit is contained in:
Jake Luer 2012-02-26 09:08:19 -08:00
commit b3e57a34ad
4 changed files with 28 additions and 2 deletions

View file

@ -100,6 +100,7 @@ require.register("assertion.js", function(module, exports, require){
var AssertionError = require('./error')
, eql = require('./utils/eql')
, toString = Object.prototype.toString
, inspect = require('./utils/inspect');
/*!
@ -125,6 +126,7 @@ function Assertion (obj, msg, stack) {
/*!
* ## Assertion.includeStack
* , toString = Object.prototype.toString
*
* User configurable property, influences whether stack trace
* is included in Assertion error message. Default of false
@ -588,8 +590,10 @@ Assertion.prototype.within = function (start, finish) {
*/
Assertion.prototype.a = function (type) {
var klass = type.charAt(0).toUpperCase() + type.slice(1);
this.assert(
type == typeof this.obj
'[object ' + klass + ']' === toString.call(this.obj)
, 'expected ' + this.inspect + ' to be a ' + type
, 'expected ' + this.inspect + ' not to be a ' + type);

View file

@ -47,6 +47,7 @@
var AssertionError = require('./error')
, eql = require('./utils/eql')
, toString = Object.prototype.toString
, inspect = require('./utils/inspect');
/*!
@ -72,6 +73,7 @@ function Assertion (obj, msg, stack) {
/*!
* ## Assertion.includeStack
* , toString = Object.prototype.toString
*
* User configurable property, influences whether stack trace
* is included in Assertion error message. Default of false
@ -535,8 +537,10 @@ Assertion.prototype.within = function (start, finish) {
*/
Assertion.prototype.a = function (type) {
var klass = type.charAt(0).toUpperCase() + type.slice(1);
this.assert(
type == typeof this.obj
'[object ' + klass + ']' === toString.call(this.obj)
, 'expected ' + this.inspect + ' to be a ' + type
, 'expected ' + this.inspect + ' not to be a ' + type);

View file

@ -95,6 +95,14 @@ suite('expect', function () {
}, "expected 'test' not to be a string");
expect(5).to.be.a('number');
expect(new Number(1)).to.be.a('number');
expect(Number(1)).to.be.a('number');
expect(true).to.be.a('boolean');
expect(new Array()).to.be.a('array');
expect(new Object()).to.be.a('object');
expect({}).to.be.a('object');
expect([]).to.be.a('array');
expect(function() {}).to.be.a('function');
err(function(){
expect(5).to.not.be.a('number');

View file

@ -101,6 +101,16 @@ suite('should', function() {
'test'.should.not.be.a('string');
}, "expected 'test' not to be a string");
(5).should.be.a('number');
(new Number(1)).should.be.a('number');
Number(1).should.be.a('number');
(true).should.be.a('boolean');
(new Array()).should.be.a('array');
(new Object()).should.be.a('object');
({}).should.be.a('object');
([]).should.be.a('array');
(function() {}).should.be.a('function');
(5).should.be.a('number');
err(function(){