mirror of
https://github.com/chaijs/chai
synced 2024-11-15 08:17:14 +00:00
commit
b3e57a34ad
4 changed files with 28 additions and 2 deletions
6
chai.js
6
chai.js
|
@ -100,6 +100,7 @@ require.register("assertion.js", function(module, exports, require){
|
||||||
|
|
||||||
var AssertionError = require('./error')
|
var AssertionError = require('./error')
|
||||||
, eql = require('./utils/eql')
|
, eql = require('./utils/eql')
|
||||||
|
, toString = Object.prototype.toString
|
||||||
, inspect = require('./utils/inspect');
|
, inspect = require('./utils/inspect');
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -125,6 +126,7 @@ function Assertion (obj, msg, stack) {
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* ## Assertion.includeStack
|
* ## Assertion.includeStack
|
||||||
|
* , toString = Object.prototype.toString
|
||||||
*
|
*
|
||||||
* User configurable property, influences whether stack trace
|
* User configurable property, influences whether stack trace
|
||||||
* is included in Assertion error message. Default of false
|
* is included in Assertion error message. Default of false
|
||||||
|
@ -588,8 +590,10 @@ Assertion.prototype.within = function (start, finish) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Assertion.prototype.a = function (type) {
|
Assertion.prototype.a = function (type) {
|
||||||
|
var klass = type.charAt(0).toUpperCase() + type.slice(1);
|
||||||
|
|
||||||
this.assert(
|
this.assert(
|
||||||
type == typeof this.obj
|
'[object ' + klass + ']' === toString.call(this.obj)
|
||||||
, 'expected ' + this.inspect + ' to be a ' + type
|
, 'expected ' + this.inspect + ' to be a ' + type
|
||||||
, 'expected ' + this.inspect + ' not to be a ' + type);
|
, 'expected ' + this.inspect + ' not to be a ' + type);
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
|
|
||||||
var AssertionError = require('./error')
|
var AssertionError = require('./error')
|
||||||
, eql = require('./utils/eql')
|
, eql = require('./utils/eql')
|
||||||
|
, toString = Object.prototype.toString
|
||||||
, inspect = require('./utils/inspect');
|
, inspect = require('./utils/inspect');
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -72,6 +73,7 @@ function Assertion (obj, msg, stack) {
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* ## Assertion.includeStack
|
* ## Assertion.includeStack
|
||||||
|
* , toString = Object.prototype.toString
|
||||||
*
|
*
|
||||||
* User configurable property, influences whether stack trace
|
* User configurable property, influences whether stack trace
|
||||||
* is included in Assertion error message. Default of false
|
* is included in Assertion error message. Default of false
|
||||||
|
@ -535,8 +537,10 @@ Assertion.prototype.within = function (start, finish) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Assertion.prototype.a = function (type) {
|
Assertion.prototype.a = function (type) {
|
||||||
|
var klass = type.charAt(0).toUpperCase() + type.slice(1);
|
||||||
|
|
||||||
this.assert(
|
this.assert(
|
||||||
type == typeof this.obj
|
'[object ' + klass + ']' === toString.call(this.obj)
|
||||||
, 'expected ' + this.inspect + ' to be a ' + type
|
, 'expected ' + this.inspect + ' to be a ' + type
|
||||||
, 'expected ' + this.inspect + ' not to be a ' + type);
|
, 'expected ' + this.inspect + ' not to be a ' + type);
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,14 @@ suite('expect', function () {
|
||||||
}, "expected 'test' not to be a string");
|
}, "expected 'test' not to be a string");
|
||||||
|
|
||||||
expect(5).to.be.a('number');
|
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(){
|
err(function(){
|
||||||
expect(5).to.not.be.a('number');
|
expect(5).to.not.be.a('number');
|
||||||
|
|
|
@ -101,6 +101,16 @@ suite('should', function() {
|
||||||
'test'.should.not.be.a('string');
|
'test'.should.not.be.a('string');
|
||||||
}, "expected 'test' not to 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');
|
(5).should.be.a('number');
|
||||||
|
|
||||||
err(function(){
|
err(function(){
|
||||||
|
|
Loading…
Reference in a new issue