mirror of
https://github.com/chaijs/chai
synced 2024-11-14 15:57:10 +00:00
Release 0.5.0
This commit is contained in:
parent
ffbce63284
commit
a1e0ae0c06
14 changed files with 547 additions and 192 deletions
32
History.md
32
History.md
|
@ -1,4 +1,36 @@
|
|||
|
||||
0.5.0 / 2012-03-07
|
||||
==================
|
||||
|
||||
* [bug] on inspect of reg on n 0.4.12
|
||||
* Merge branch 'bug/33-throws'
|
||||
* Merge pull request #35 from logicalparadox/empty-object
|
||||
* browser build
|
||||
* updated #throw docs
|
||||
* Assertion#throw `should` tests updated
|
||||
* Assertion#throw `expect` tests
|
||||
* Should interface supports multiple throw parameters
|
||||
* Update Assertion#throw to support strings and type checks.
|
||||
* Add more tests for `empty` in `should`.
|
||||
* Add more tests for `empty` in `expect`.
|
||||
* Merge branch 'master' into empty-object
|
||||
* don't switch act/exp
|
||||
* Merge pull request #34 from logicalparadox/assert-operator
|
||||
* Update the compiled verison.
|
||||
* Add `assert.operator`.
|
||||
* Notes on messages. #22
|
||||
* browser build
|
||||
* have been test
|
||||
* below tests
|
||||
* Merge branch 'feature/actexp'
|
||||
* browser build
|
||||
* remove unnecessary fail export
|
||||
* full support for actual/expected where relevant
|
||||
* Assertion.assert support expected value
|
||||
* clean up error
|
||||
* Update the compiled version.
|
||||
* Add object & sane arguments support to `Assertion#empty`.
|
||||
|
||||
0.4.2 / 2012-02-28
|
||||
==================
|
||||
|
||||
|
|
6
chai.js
6
chai.js
|
@ -947,8 +947,8 @@ Assertion.prototype.throw = function (constructor, msg) {
|
|||
if (err.message && msg && msg instanceof RegExp) {
|
||||
this.assert(
|
||||
msg.exec(err.message)
|
||||
, 'expected ' + this.inspect + ' to throw error matching ' + inspect(msg) + ' but got ' + inspect(err.message)
|
||||
, 'expected ' + this.inspect + ' to throw error not matching ' + inspect(msg)
|
||||
, 'expected ' + this.inspect + ' to throw error matching ' + msg + ' but got ' + inspect(err.message)
|
||||
, 'expected ' + this.inspect + ' to throw error not matching ' + msg
|
||||
);
|
||||
return this;
|
||||
} else if (err.message && msg && 'string' === typeof msg) {
|
||||
|
@ -1077,7 +1077,7 @@ require.register("chai.js", function(module, exports, require){
|
|||
var used = [];
|
||||
var exports = module.exports = {};
|
||||
|
||||
exports.version = '0.4.2';
|
||||
exports.version = '0.5.0';
|
||||
|
||||
exports.Assertion = require('./assertion');
|
||||
exports.AssertionError = require('./error');
|
||||
|
|
|
@ -39,12 +39,13 @@ If you have made changes to any of the components, you must rebuild the browser
|
|||
|
||||
### Contributors
|
||||
|
||||
commits: 185
|
||||
commits: 252
|
||||
files : 71
|
||||
authors:
|
||||
163 Jake Luer 88.1%
|
||||
16 Veselin Todorov 8.6%
|
||||
3 Jeff Barczewski 1.6%
|
||||
1 Domenic Denicola 0.5%
|
||||
1 John Firebaugh 0.5%
|
||||
1 Vinay Pulim 0.5%
|
||||
192 Jake Luer 76.2%
|
||||
53 Veselin Todorov 21.0%
|
||||
3 Jeff Barczewski 1.2%
|
||||
1 Vinay Pulim 0.4%
|
||||
1 Jo Liss 0.4%
|
||||
1 Domenic Denicola 0.4%
|
||||
1 John Firebaugh 0.4%
|
||||
|
|
|
@ -4,4 +4,7 @@
|
|||
render-file: false
|
||||
---
|
||||
|
||||
If you have questions or issues, please use this projects [Github Issues](https://github.com/logicalparadox/chai/issues).
|
||||
If you have questions or issues, please use this projects
|
||||
[Github Issues](https://github.com/logicalparadox/chai/issues). You can also keep up to date
|
||||
on the [Google Group](http://groups.google.com/group/chaijs) or ping [@jakeluer](http://twitter.com/jakeluer)
|
||||
directly on Twitter. Chai developers can also be found on Freenode IRC in #letstest.js.
|
||||
|
|
249
docs/out/chai.js
249
docs/out/chai.js
|
@ -126,7 +126,7 @@ function Assertion (obj, msg, stack) {
|
|||
|
||||
/*!
|
||||
* ## Assertion.includeStack
|
||||
* , toString = Object.prototype.toString
|
||||
* , toString = Object.prototype.toString
|
||||
*
|
||||
* User configurable property, influences whether stack trace
|
||||
* is included in Assertion error message. Default of false
|
||||
|
@ -151,15 +151,17 @@ Assertion.includeStack = false;
|
|||
* @api private
|
||||
*/
|
||||
|
||||
Assertion.prototype.assert = function (expr, msg, negateMsg) {
|
||||
Assertion.prototype.assert = function (expr, msg, negateMsg, expected, actual) {
|
||||
actual = actual || this.obj;
|
||||
var msg = (this.negate ? negateMsg : msg)
|
||||
, ok = this.negate ? !expr : expr;
|
||||
|
||||
if (!ok) {
|
||||
throw new AssertionError({
|
||||
operator: this.msg,
|
||||
message: msg,
|
||||
stackStartFunction: (Assertion.includeStack) ? this.assert : this.ssfi
|
||||
message: this.msg ? this.msg + ': ' + msg : msg // include custom message if available
|
||||
, actual: actual
|
||||
, expected: expected
|
||||
, stackStartFunction: (Assertion.includeStack) ? this.assert : this.ssfi
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -176,8 +178,8 @@ Assertion.prototype.assert = function (expr, msg, negateMsg) {
|
|||
Object.defineProperty(Assertion.prototype, 'inspect',
|
||||
{ get: function () {
|
||||
return inspect(this.obj);
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -192,8 +194,8 @@ Object.defineProperty(Assertion.prototype, 'inspect',
|
|||
Object.defineProperty(Assertion.prototype, 'to',
|
||||
{ get: function () {
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -208,8 +210,8 @@ Object.defineProperty(Assertion.prototype, 'to',
|
|||
Object.defineProperty(Assertion.prototype, 'be',
|
||||
{ get: function () {
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -226,8 +228,8 @@ Object.defineProperty(Assertion.prototype, 'been',
|
|||
{ get: function () {
|
||||
this.tense = 'past';
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -242,8 +244,8 @@ Object.defineProperty(Assertion.prototype, 'been',
|
|||
Object.defineProperty(Assertion.prototype, 'an',
|
||||
{ get: function () {
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});
|
||||
/**
|
||||
* # is
|
||||
|
@ -257,8 +259,8 @@ Object.defineProperty(Assertion.prototype, 'an',
|
|||
Object.defineProperty(Assertion.prototype, 'is',
|
||||
{ get: function () {
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -273,8 +275,8 @@ Object.defineProperty(Assertion.prototype, 'is',
|
|||
Object.defineProperty(Assertion.prototype, 'and',
|
||||
{ get: function () {
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -289,8 +291,8 @@ Object.defineProperty(Assertion.prototype, 'and',
|
|||
Object.defineProperty(Assertion.prototype, 'have',
|
||||
{ get: function () {
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -305,8 +307,8 @@ Object.defineProperty(Assertion.prototype, 'have',
|
|||
Object.defineProperty(Assertion.prototype, 'with',
|
||||
{ get: function () {
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -322,8 +324,8 @@ Object.defineProperty(Assertion.prototype, 'not',
|
|||
{ get: function () {
|
||||
this.negate = true;
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -348,8 +350,8 @@ Object.defineProperty(Assertion.prototype, 'ok',
|
|||
, 'expected ' + this.inspect + ' to be falsy');
|
||||
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -366,11 +368,13 @@ Object.defineProperty(Assertion.prototype, 'true',
|
|||
this.assert(
|
||||
true === this.obj
|
||||
, 'expected ' + this.inspect + ' to be true'
|
||||
, 'expected ' + this.inspect + ' to be false');
|
||||
, 'expected ' + this.inspect + ' to be false'
|
||||
, this.negate ? false : true
|
||||
);
|
||||
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -387,11 +391,13 @@ Object.defineProperty(Assertion.prototype, 'false',
|
|||
this.assert(
|
||||
false === this.obj
|
||||
, 'expected ' + this.inspect + ' to be false'
|
||||
, 'expected ' + this.inspect + ' to be true');
|
||||
, 'expected ' + this.inspect + ' to be true'
|
||||
, this.negate ? true : false
|
||||
);
|
||||
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -413,11 +419,12 @@ Object.defineProperty(Assertion.prototype, 'exist',
|
|||
this.assert(
|
||||
null != this.obj
|
||||
, 'expected ' + this.inspect + ' to exist'
|
||||
, 'expected ' + this.inspect + ' to not exist');
|
||||
, 'expected ' + this.inspect + ' to not exist'
|
||||
);
|
||||
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -433,16 +440,22 @@ Object.defineProperty(Assertion.prototype, 'exist',
|
|||
|
||||
Object.defineProperty(Assertion.prototype, 'empty',
|
||||
{ get: function () {
|
||||
new Assertion(this.obj).to.have.property('length');
|
||||
var expected = this.obj;
|
||||
|
||||
if (Array.isArray(this.obj)) {
|
||||
expected = this.obj.length;
|
||||
} else if (typeof this.obj === 'object') {
|
||||
expected = Object.keys(this.obj).length;
|
||||
}
|
||||
|
||||
this.assert(
|
||||
0 === this.obj.length
|
||||
!expected
|
||||
, 'expected ' + this.inspect + ' to be empty'
|
||||
, 'expected ' + this.inspect + ' not to be empty');
|
||||
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -463,11 +476,14 @@ Object.defineProperty(Assertion.prototype, 'arguments',
|
|||
this.assert(
|
||||
'[object Arguments]' == Object.prototype.toString.call(this.obj)
|
||||
, 'expected ' + this.inspect + ' to be arguments'
|
||||
, 'expected ' + this.inspect + ' to not be arguments');
|
||||
, 'expected ' + this.inspect + ' to not be arguments'
|
||||
, '[object Arguments]'
|
||||
, Object.prototype.toString.call(this.obj)
|
||||
);
|
||||
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -486,7 +502,8 @@ Assertion.prototype.equal = function (val) {
|
|||
this.assert(
|
||||
val === this.obj
|
||||
, 'expected ' + this.inspect + ' to equal ' + inspect(val)
|
||||
, 'expected ' + this.inspect + ' to not equal ' + inspect(val));
|
||||
, 'expected ' + this.inspect + ' to not equal ' + inspect(val)
|
||||
, val );
|
||||
|
||||
return this;
|
||||
};
|
||||
|
@ -507,7 +524,9 @@ Assertion.prototype.eql = function (obj) {
|
|||
this.assert(
|
||||
eql(obj, this.obj)
|
||||
, 'expected ' + this.inspect + ' to equal ' + inspect(obj)
|
||||
, 'expected ' + this.inspect + ' to not equal ' + inspect(obj));
|
||||
, 'expected ' + this.inspect + ' to not equal ' + inspect(obj)
|
||||
, obj );
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
|
@ -595,7 +614,10 @@ Assertion.prototype.a = function (type) {
|
|||
this.assert(
|
||||
'[object ' + klass + ']' === toString.call(this.obj)
|
||||
, 'expected ' + this.inspect + ' to be a ' + type
|
||||
, 'expected ' + this.inspect + ' not to be a ' + type);
|
||||
, 'expected ' + this.inspect + ' not to be a ' + type
|
||||
, '[object ' + klass + ']'
|
||||
, toString.call(this.obj)
|
||||
);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
@ -660,7 +682,10 @@ Assertion.prototype.property = function (name, val) {
|
|||
val === this.obj[name]
|
||||
, 'expected ' + this.inspect + ' to have a property ' + inspect(name) + ' of ' +
|
||||
inspect(val) + ', but got ' + inspect(this.obj[name])
|
||||
, 'expected ' + this.inspect + ' to not have a property ' + inspect(name) + ' of ' + inspect(val));
|
||||
, 'expected ' + this.inspect + ' to not have a property ' + inspect(name) + ' of ' + inspect(val)
|
||||
, val
|
||||
, this.obj[val]
|
||||
);
|
||||
}
|
||||
|
||||
this.obj = this.obj[name];
|
||||
|
@ -709,7 +734,10 @@ Assertion.prototype.length = function (n) {
|
|||
this.assert(
|
||||
len == n
|
||||
, 'expected ' + this.inspect + ' to have a length of ' + n + ' but got ' + len
|
||||
, 'expected ' + this.inspect + ' to not have a length of ' + len);
|
||||
, 'expected ' + this.inspect + ' to not have a length of ' + len
|
||||
, n
|
||||
, len
|
||||
);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
@ -856,7 +884,10 @@ Assertion.prototype.keys = function(keys) {
|
|||
this.assert(
|
||||
ok
|
||||
, 'expected ' + this.inspect + ' to ' + str
|
||||
, 'expected ' + this.inspect + ' to not ' + str);
|
||||
, 'expected ' + this.inspect + ' to not ' + str
|
||||
, keys
|
||||
, Object.keys(this.obj)
|
||||
);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -864,10 +895,21 @@ Assertion.prototype.keys = function(keys) {
|
|||
/**
|
||||
* # .throw(constructor)
|
||||
*
|
||||
* Assert that a function will throw a specific type of error.
|
||||
* Assert that a function will throw a specific type of error or that error
|
||||
* thrown will match a RegExp or include a string.
|
||||
*
|
||||
* var fn = function () { throw new ReferenceError(''); }
|
||||
* var fn = function () { throw new ReferenceError('This is a bad function.'); }
|
||||
* expect(fn).to.throw(ReferenceError);
|
||||
* expect(fn).to.throw(/bad function/);
|
||||
* expect(fn).to.not.throw('good function');
|
||||
* expect(fn).to.throw(ReferenceError, /bad function/);
|
||||
*
|
||||
* Please note that when a throw expectation is negated, it will check each
|
||||
* parameter independently, starting with Error constructor type. The appropriate way
|
||||
* to check for the existence of a type of error but for a message that does not match
|
||||
* is to use `and`.
|
||||
*
|
||||
* expect(fn).to.throw(ReferenceError).and.not.throw(/good function/);
|
||||
*
|
||||
* @name throw
|
||||
* @alias throws
|
||||
|
@ -877,25 +919,44 @@ Assertion.prototype.keys = function(keys) {
|
|||
* @api public
|
||||
*/
|
||||
|
||||
Assertion.prototype.throw = function (constructor) {
|
||||
Assertion.prototype.throw = function (constructor, msg) {
|
||||
new Assertion(this.obj).is.a('function');
|
||||
|
||||
var thrown = false;
|
||||
|
||||
if (arguments.length === 0) {
|
||||
msg = null;
|
||||
constructor = null;
|
||||
} else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {
|
||||
msg = constructor;
|
||||
constructor = null;
|
||||
}
|
||||
|
||||
try {
|
||||
this.obj();
|
||||
} catch (err) {
|
||||
if (constructor && 'function' === typeof constructor && constructor.constructor != RegExp) {
|
||||
// first, check constructor
|
||||
if (constructor && 'function' === typeof constructor) {
|
||||
this.assert(
|
||||
err instanceof constructor && err.name == constructor.name
|
||||
, 'expected ' + this.inspect + ' to throw ' + constructor.name + ' but a ' + err.name + ' was thrown'
|
||||
, 'expected ' + this.inspect + ' to not throw ' + constructor.name );
|
||||
return this;
|
||||
} else if (constructor && constructor instanceof RegExp) {
|
||||
if (!msg) return this;
|
||||
}
|
||||
// next, check message
|
||||
if (err.message && msg && msg instanceof RegExp) {
|
||||
this.assert(
|
||||
constructor.exec(err.message)
|
||||
, 'expected ' + this.inspect + ' to throw error matching ' + constructor + ' but got ' + inspect(err.message)
|
||||
, 'expected ' + this.inspect + ' to throw error not matching ' + constructor);
|
||||
msg.exec(err.message)
|
||||
, 'expected ' + this.inspect + ' to throw error matching ' + msg + ' but got ' + inspect(err.message)
|
||||
, 'expected ' + this.inspect + ' to throw error not matching ' + msg
|
||||
);
|
||||
return this;
|
||||
} else if (err.message && msg && 'string' === typeof msg) {
|
||||
this.assert(
|
||||
~err.message.indexOf(msg)
|
||||
, 'expected ' + this.inspect + ' to throw error including ' + inspect(msg) + ' but got ' + inspect(err.message)
|
||||
, 'expected ' + this.inspect + ' to throw error not including ' + inspect(msg)
|
||||
);
|
||||
return this;
|
||||
} else {
|
||||
thrown = true;
|
||||
|
@ -933,7 +994,10 @@ Assertion.prototype.respondTo = function (method) {
|
|||
this.assert(
|
||||
'function' === typeof context
|
||||
, 'expected ' + this.inspect + ' to respond to ' + inspect(method)
|
||||
, 'expected ' + this.inspect + ' to not respond to ' + inspect(method));
|
||||
, 'expected ' + this.inspect + ' to not respond to ' + inspect(method)
|
||||
, 'function'
|
||||
, typeof context
|
||||
);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
@ -954,7 +1018,10 @@ Assertion.prototype.satisfy = function (matcher) {
|
|||
this.assert(
|
||||
matcher(this.obj)
|
||||
, 'expected ' + this.inspect + ' to satisfy ' + inspect(matcher)
|
||||
, 'expected ' + this.inspect + ' to not satisfy' + inspect(matcher));
|
||||
, 'expected ' + this.inspect + ' to not satisfy' + inspect(matcher)
|
||||
, this.negate ? false : true
|
||||
, matcher(this.obj)
|
||||
);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
@ -1010,7 +1077,7 @@ require.register("chai.js", function(module, exports, require){
|
|||
var used = [];
|
||||
var exports = module.exports = {};
|
||||
|
||||
exports.version = '0.4.2';
|
||||
exports.version = '0.5.0';
|
||||
|
||||
exports.Assertion = require('./assertion');
|
||||
exports.AssertionError = require('./error');
|
||||
|
@ -1026,16 +1093,6 @@ exports.use = function (fn) {
|
|||
return this;
|
||||
};
|
||||
|
||||
exports.fail = function (actual, expected, message, operator, stackStartFunction) {
|
||||
throw new exports.AssertionError({
|
||||
message: message,
|
||||
actual: actual,
|
||||
expected: expected,
|
||||
operator: operator,
|
||||
stackStartFunction: stackStartFunction
|
||||
});
|
||||
};
|
||||
|
||||
var expect = require('./interface/expect');
|
||||
exports.use(expect);
|
||||
|
||||
|
@ -1078,25 +1135,10 @@ function AssertionError (options) {
|
|||
|
||||
AssertionError.prototype.__proto__ = Error.prototype;
|
||||
|
||||
AssertionError.prototype.summary = function() {
|
||||
var str = '';
|
||||
|
||||
if (this.operator) {
|
||||
str += 'In: \'' + this.operator + '\'\n\t';
|
||||
}
|
||||
|
||||
str += '' + this.name + (this.message ? ': ' + this.message : '');
|
||||
|
||||
return str;
|
||||
};
|
||||
|
||||
AssertionError.prototype.details = function() {
|
||||
return this.summary();
|
||||
};
|
||||
|
||||
AssertionError.prototype.toString = function() {
|
||||
return this.summary();
|
||||
return this.message;
|
||||
};
|
||||
|
||||
}); // module: error.js
|
||||
|
||||
require.register("interface/assert.js", function(module, exports, require){
|
||||
|
@ -1632,6 +1674,29 @@ module.exports = function (chai) {
|
|||
new Assertion(fn, msg).to.not.throw(type);
|
||||
};
|
||||
|
||||
/**
|
||||
* # .operator(val, operator, val2, [message])
|
||||
*
|
||||
* Compare two values using operator.
|
||||
*
|
||||
* assert.operator(1, '<', 2, 'everything is ok');
|
||||
* assert.operator(1, '>', 2, 'this will fail');
|
||||
*
|
||||
* @name operator
|
||||
* @param {*} object to test
|
||||
* @param {String} operator
|
||||
* @param {*} second object
|
||||
* @param {String} message
|
||||
* @api public
|
||||
*/
|
||||
|
||||
assert.operator = function (val, operator, val2, msg) {
|
||||
if (!~['==', '===', '>', '>=', '<', '<=', '!=', '!=='].indexOf(operator)) {
|
||||
throw new Error('Invalid operator "' + operator + '"');
|
||||
}
|
||||
new Assertion(eval(val + operator + val2), msg).to.be.true;
|
||||
};
|
||||
|
||||
/*!
|
||||
* Undocumented / untested
|
||||
*/
|
||||
|
@ -1701,8 +1766,8 @@ module.exports = function (chai) {
|
|||
new Assertion(val1).to.equal(val2);
|
||||
};
|
||||
|
||||
should.throw = function (fn, err) {
|
||||
new Assertion(fn).to.throw(err);
|
||||
should.throw = function (fn, errt, errs) {
|
||||
new Assertion(fn).to.throw(errt, errs);
|
||||
};
|
||||
|
||||
should.exist = function (val) {
|
||||
|
@ -1716,8 +1781,8 @@ module.exports = function (chai) {
|
|||
new Assertion(val1).to.not.equal(val2);
|
||||
};
|
||||
|
||||
should.not.throw = function (fn, err) {
|
||||
new Assertion(fn).to.not.throw(err);
|
||||
should.not.throw = function (fn, errt, errs) {
|
||||
new Assertion(fn).to.not.throw(errt, errs);
|
||||
};
|
||||
|
||||
should.not.exist = function (val) {
|
||||
|
|
|
@ -92,6 +92,8 @@ _gaq.push(['_trackPageview']);
|
|||
</li>
|
||||
<li class="keepcase"><a href="#doesNotThrow" class="scroll">doesNotThrow</a>
|
||||
</li>
|
||||
<li class="keepcase"><a href="#operator" class="scroll">operator</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1002,6 +1004,44 @@ _gaq.push(['_trackPageview']);
|
|||
}
|
||||
|
||||
new Assertion(fn, msg).to.not.throw(type);
|
||||
};</code>
|
||||
</pre>
|
||||
</div>
|
||||
</article>
|
||||
<article id="operator-section" class="codeblock">
|
||||
<div class="header"><h1>.operator(val, operator, val2, [message])</h1>
|
||||
</div>
|
||||
<div class="ctx">
|
||||
<h3>assert.operator()
|
||||
</h3>
|
||||
</div>
|
||||
<div class="tags">
|
||||
<!-- ignroing this-->
|
||||
<div class="tag"><span class="type">@param</span><span class="types">{ * }</span><span class="name">object</span><span class="desc">to test</span>
|
||||
</div>
|
||||
<div class="tag"><span class="type">@param</span><span class="types">{ String }</span><span class="name">operator</span><span class="desc"></span>
|
||||
</div>
|
||||
<div class="tag"><span class="type">@param</span><span class="types">{ * }</span><span class="name">second</span><span class="desc">object</span>
|
||||
</div>
|
||||
<div class="tag"><span class="type">@param</span><span class="types">{ String }</span><span class="name">message</span><span class="desc"></span>
|
||||
</div>
|
||||
<div class="tag"><span class="type">@api</span><span class="visibility">public</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="description"><p>Compare two values using operator.</p>
|
||||
|
||||
<pre><code> assert.operator(1, '<', 2, 'everything is ok');
|
||||
assert.operator(1, '>', 2, 'this will fail');
|
||||
</code></pre>
|
||||
</div>
|
||||
<div class="view-source">View Source
|
||||
</div>
|
||||
<div class="code-wrap">
|
||||
<pre class="source prettyprint"><code>assert.operator = function (val, operator, val2, msg) {
|
||||
if (!~['==', '===', '>', '>=', '<', '<=', '!=', '!=='].indexOf(operator)) {
|
||||
throw new Error('Invalid operator "' + operator + '"');
|
||||
}
|
||||
new Assertion(eval(val + operator + val2), msg).to.be.true;
|
||||
};</code>
|
||||
</pre>
|
||||
</div>
|
||||
|
|
|
@ -210,8 +210,8 @@ _gaq.push(['_trackPageview']);
|
|||
<pre class="source prettyprint"><code>Object.defineProperty(Assertion.prototype, 'to',
|
||||
{ get: function () {
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});</code>
|
||||
</pre>
|
||||
</div>
|
||||
|
@ -232,8 +232,8 @@ _gaq.push(['_trackPageview']);
|
|||
<pre class="source prettyprint"><code>Object.defineProperty(Assertion.prototype, 'be',
|
||||
{ get: function () {
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});</code>
|
||||
</pre>
|
||||
</div>
|
||||
|
@ -255,8 +255,8 @@ _gaq.push(['_trackPageview']);
|
|||
{ get: function () {
|
||||
this.tense = 'past';
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});</code>
|
||||
</pre>
|
||||
</div>
|
||||
|
@ -277,8 +277,8 @@ _gaq.push(['_trackPageview']);
|
|||
<pre class="source prettyprint"><code>Object.defineProperty(Assertion.prototype, 'an',
|
||||
{ get: function () {
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});</code>
|
||||
</pre>
|
||||
</div>
|
||||
|
@ -299,8 +299,8 @@ _gaq.push(['_trackPageview']);
|
|||
<pre class="source prettyprint"><code>Object.defineProperty(Assertion.prototype, 'is',
|
||||
{ get: function () {
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});</code>
|
||||
</pre>
|
||||
</div>
|
||||
|
@ -321,8 +321,8 @@ _gaq.push(['_trackPageview']);
|
|||
<pre class="source prettyprint"><code>Object.defineProperty(Assertion.prototype, 'and',
|
||||
{ get: function () {
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});</code>
|
||||
</pre>
|
||||
</div>
|
||||
|
@ -343,8 +343,8 @@ _gaq.push(['_trackPageview']);
|
|||
<pre class="source prettyprint"><code>Object.defineProperty(Assertion.prototype, 'have',
|
||||
{ get: function () {
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});</code>
|
||||
</pre>
|
||||
</div>
|
||||
|
@ -365,8 +365,8 @@ _gaq.push(['_trackPageview']);
|
|||
<pre class="source prettyprint"><code>Object.defineProperty(Assertion.prototype, 'with',
|
||||
{ get: function () {
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});</code>
|
||||
</pre>
|
||||
</div>
|
||||
|
@ -388,8 +388,8 @@ _gaq.push(['_trackPageview']);
|
|||
{ get: function () {
|
||||
this.negate = true;
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});</code>
|
||||
</pre>
|
||||
</div>
|
||||
|
@ -421,8 +421,8 @@ _gaq.push(['_trackPageview']);
|
|||
, 'expected ' + this.inspect + ' to be falsy');
|
||||
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});</code>
|
||||
</pre>
|
||||
</div>
|
||||
|
@ -445,11 +445,13 @@ _gaq.push(['_trackPageview']);
|
|||
this.assert(
|
||||
true === this.obj
|
||||
, 'expected ' + this.inspect + ' to be true'
|
||||
, 'expected ' + this.inspect + ' to be false');
|
||||
, 'expected ' + this.inspect + ' to be false'
|
||||
, this.negate ? false : true
|
||||
);
|
||||
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});</code>
|
||||
</pre>
|
||||
</div>
|
||||
|
@ -472,11 +474,13 @@ _gaq.push(['_trackPageview']);
|
|||
this.assert(
|
||||
false === this.obj
|
||||
, 'expected ' + this.inspect + ' to be false'
|
||||
, 'expected ' + this.inspect + ' to be true');
|
||||
, 'expected ' + this.inspect + ' to be true'
|
||||
, this.negate ? true : false
|
||||
);
|
||||
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});</code>
|
||||
</pre>
|
||||
</div>
|
||||
|
@ -505,11 +509,12 @@ _gaq.push(['_trackPageview']);
|
|||
this.assert(
|
||||
null != this.obj
|
||||
, 'expected ' + this.inspect + ' to exist'
|
||||
, 'expected ' + this.inspect + ' to not exist');
|
||||
, 'expected ' + this.inspect + ' to not exist'
|
||||
);
|
||||
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});</code>
|
||||
</pre>
|
||||
</div>
|
||||
|
@ -532,16 +537,22 @@ _gaq.push(['_trackPageview']);
|
|||
<div class="code-wrap">
|
||||
<pre class="source prettyprint"><code>Object.defineProperty(Assertion.prototype, 'empty',
|
||||
{ get: function () {
|
||||
new Assertion(this.obj).to.have.property('length');
|
||||
var expected = this.obj;
|
||||
|
||||
if (Array.isArray(this.obj)) {
|
||||
expected = this.obj.length;
|
||||
} else if (typeof this.obj === 'object') {
|
||||
expected = Object.keys(this.obj).length;
|
||||
}
|
||||
|
||||
this.assert(
|
||||
0 === this.obj.length
|
||||
!expected
|
||||
, 'expected ' + this.inspect + ' to be empty'
|
||||
, 'expected ' + this.inspect + ' not to be empty');
|
||||
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});</code>
|
||||
</pre>
|
||||
</div>
|
||||
|
@ -569,11 +580,14 @@ _gaq.push(['_trackPageview']);
|
|||
this.assert(
|
||||
'[object Arguments]' == Object.prototype.toString.call(this.obj)
|
||||
, 'expected ' + this.inspect + ' to be arguments'
|
||||
, 'expected ' + this.inspect + ' to not be arguments');
|
||||
, 'expected ' + this.inspect + ' to not be arguments'
|
||||
, '[object Arguments]'
|
||||
, Object.prototype.toString.call(this.obj)
|
||||
);
|
||||
|
||||
return this;
|
||||
},
|
||||
configurable: true
|
||||
}
|
||||
, configurable: true
|
||||
});</code>
|
||||
</pre>
|
||||
</div>
|
||||
|
@ -604,7 +618,8 @@ _gaq.push(['_trackPageview']);
|
|||
this.assert(
|
||||
val === this.obj
|
||||
, 'expected ' + this.inspect + ' to equal ' + inspect(val)
|
||||
, 'expected ' + this.inspect + ' to not equal ' + inspect(val));
|
||||
, 'expected ' + this.inspect + ' to not equal ' + inspect(val)
|
||||
, val );
|
||||
|
||||
return this;
|
||||
};</code>
|
||||
|
@ -637,7 +652,9 @@ _gaq.push(['_trackPageview']);
|
|||
this.assert(
|
||||
eql(obj, this.obj)
|
||||
, 'expected ' + this.inspect + ' to equal ' + inspect(obj)
|
||||
, 'expected ' + this.inspect + ' to not equal ' + inspect(obj));
|
||||
, 'expected ' + this.inspect + ' to not equal ' + inspect(obj)
|
||||
, obj );
|
||||
|
||||
return this;
|
||||
};</code>
|
||||
</pre>
|
||||
|
@ -774,7 +791,10 @@ _gaq.push(['_trackPageview']);
|
|||
this.assert(
|
||||
'[object ' + klass + ']' === toString.call(this.obj)
|
||||
, 'expected ' + this.inspect + ' to be a ' + type
|
||||
, 'expected ' + this.inspect + ' not to be a ' + type);
|
||||
, 'expected ' + this.inspect + ' not to be a ' + type
|
||||
, '[object ' + klass + ']'
|
||||
, toString.call(this.obj)
|
||||
);
|
||||
|
||||
return this;
|
||||
};</code>
|
||||
|
@ -866,7 +886,10 @@ _gaq.push(['_trackPageview']);
|
|||
val === this.obj[name]
|
||||
, 'expected ' + this.inspect + ' to have a property ' + inspect(name) + ' of ' +
|
||||
inspect(val) + ', but got ' + inspect(this.obj[name])
|
||||
, 'expected ' + this.inspect + ' to not have a property ' + inspect(name) + ' of ' + inspect(val));
|
||||
, 'expected ' + this.inspect + ' to not have a property ' + inspect(name) + ' of ' + inspect(val)
|
||||
, val
|
||||
, this.obj[val]
|
||||
);
|
||||
}
|
||||
|
||||
this.obj = this.obj[name];
|
||||
|
@ -941,7 +964,10 @@ _gaq.push(['_trackPageview']);
|
|||
this.assert(
|
||||
len == n
|
||||
, 'expected ' + this.inspect + ' to have a length of ' + n + ' but got ' + len
|
||||
, 'expected ' + this.inspect + ' to not have a length of ' + len);
|
||||
, 'expected ' + this.inspect + ' to not have a length of ' + len
|
||||
, n
|
||||
, len
|
||||
);
|
||||
|
||||
return this;
|
||||
};</code>
|
||||
|
@ -1141,7 +1167,10 @@ _gaq.push(['_trackPageview']);
|
|||
this.assert(
|
||||
ok
|
||||
, 'expected ' + this.inspect + ' to ' + str
|
||||
, 'expected ' + this.inspect + ' to not ' + str);
|
||||
, 'expected ' + this.inspect + ' to not ' + str
|
||||
, keys
|
||||
, Object.keys(this.obj)
|
||||
);
|
||||
|
||||
return this;
|
||||
}</code>
|
||||
|
@ -1168,34 +1197,61 @@ _gaq.push(['_trackPageview']);
|
|||
<div class="tag"><span class="type">@api</span><span class="visibility">public</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="description"><p>Assert that a function will throw a specific type of error.</p>
|
||||
<div class="description"><p>Assert that a function will throw a specific type of error or that error<br />thrown will match a RegExp or include a string.</p>
|
||||
|
||||
<pre><code> var fn = function () { throw new ReferenceError(''); }
|
||||
<pre><code> var fn = function () { throw new ReferenceError('This is a bad function.'); }
|
||||
expect(fn).to.throw(ReferenceError);
|
||||
expect(fn).to.throw(/bad function/);
|
||||
expect(fn).to.not.throw('good function');
|
||||
expect(fn).to.throw(ReferenceError, /bad function/);
|
||||
</code></pre>
|
||||
|
||||
<p>Please note that when a throw expectation is negated, it will check each<br />parameter independently, starting with Error constructor type. The appropriate way<br />to check for the existence of a type of error but for a message that does not match<br />is to use <code>and</code>.</p>
|
||||
|
||||
<pre><code> expect(fn).to.throw(ReferenceError).and.not.throw(/good function/);
|
||||
</code></pre>
|
||||
</div>
|
||||
<div class="view-source">View Source
|
||||
</div>
|
||||
<div class="code-wrap">
|
||||
<pre class="source prettyprint"><code>Assertion.prototype.throw = function (constructor) {
|
||||
<pre class="source prettyprint"><code>Assertion.prototype.throw = function (constructor, msg) {
|
||||
new Assertion(this.obj).is.a('function');
|
||||
|
||||
var thrown = false;
|
||||
|
||||
if (arguments.length === 0) {
|
||||
msg = null;
|
||||
constructor = null;
|
||||
} else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {
|
||||
msg = constructor;
|
||||
constructor = null;
|
||||
}
|
||||
|
||||
try {
|
||||
this.obj();
|
||||
} catch (err) {
|
||||
if (constructor && 'function' === typeof constructor && constructor.constructor != RegExp) {
|
||||
// first, check constructor
|
||||
if (constructor && 'function' === typeof constructor) {
|
||||
this.assert(
|
||||
err instanceof constructor && err.name == constructor.name
|
||||
, 'expected ' + this.inspect + ' to throw ' + constructor.name + ' but a ' + err.name + ' was thrown'
|
||||
, 'expected ' + this.inspect + ' to not throw ' + constructor.name );
|
||||
return this;
|
||||
} else if (constructor && constructor instanceof RegExp) {
|
||||
if (!msg) return this;
|
||||
}
|
||||
// next, check message
|
||||
if (err.message && msg && msg instanceof RegExp) {
|
||||
this.assert(
|
||||
constructor.exec(err.message)
|
||||
, 'expected ' + this.inspect + ' to throw error matching ' + constructor + ' but got ' + inspect(err.message)
|
||||
, 'expected ' + this.inspect + ' to throw error not matching ' + constructor);
|
||||
msg.exec(err.message)
|
||||
, 'expected ' + this.inspect + ' to throw error matching ' + msg + ' but got ' + inspect(err.message)
|
||||
, 'expected ' + this.inspect + ' to throw error not matching ' + msg
|
||||
);
|
||||
return this;
|
||||
} else if (err.message && msg && 'string' === typeof msg) {
|
||||
this.assert(
|
||||
~err.message.indexOf(msg)
|
||||
, 'expected ' + this.inspect + ' to throw error including ' + inspect(msg) + ' but got ' + inspect(err.message)
|
||||
, 'expected ' + this.inspect + ' to throw error not including ' + inspect(msg)
|
||||
);
|
||||
return this;
|
||||
} else {
|
||||
thrown = true;
|
||||
|
@ -1245,7 +1301,10 @@ _gaq.push(['_trackPageview']);
|
|||
this.assert(
|
||||
'function' === typeof context
|
||||
, 'expected ' + this.inspect + ' to respond to ' + inspect(method)
|
||||
, 'expected ' + this.inspect + ' to not respond to ' + inspect(method));
|
||||
, 'expected ' + this.inspect + ' to not respond to ' + inspect(method)
|
||||
, 'function'
|
||||
, typeof context
|
||||
);
|
||||
|
||||
return this;
|
||||
};</code>
|
||||
|
@ -1278,7 +1337,10 @@ _gaq.push(['_trackPageview']);
|
|||
this.assert(
|
||||
matcher(this.obj)
|
||||
, 'expected ' + this.inspect + ' to satisfy ' + inspect(matcher)
|
||||
, 'expected ' + this.inspect + ' to not satisfy' + inspect(matcher));
|
||||
, 'expected ' + this.inspect + ' to not satisfy' + inspect(matcher)
|
||||
, this.negate ? false : true
|
||||
, matcher(this.obj)
|
||||
);
|
||||
|
||||
return this;
|
||||
};</code>
|
||||
|
|
|
@ -192,7 +192,10 @@ assertions for the Sinon.js mocking framework.</li>
|
|||
</section>
|
||||
<h1 id="help-section"><a name="help">Getting Help</a>
|
||||
</h1>
|
||||
<section><p>If you have questions or issues, please use this projects <a href="https://github.com/logicalparadox/chai/issues">Github Issues</a>.
|
||||
<section><p>If you have questions or issues, please use this projects
|
||||
<a href="https://github.com/logicalparadox/chai/issues">Github Issues</a>. You can also keep up to date
|
||||
on the <a href="http://groups.google.com/group/chaijs">Google Group</a> or ping <a href="http://twitter.com/jakeluer">@jakeluer</a>
|
||||
directly on Twitter. Chai developers can also be found on Freenode IRC in #letstest.js.
|
||||
</p>
|
||||
|
||||
</section>
|
||||
|
@ -230,15 +233,16 @@ in other browsers or other version.
|
|||
</p>
|
||||
<pre><code> $ make</code></pre>
|
||||
<h3>Contributors</h3>
|
||||
<pre><code> commits: 185
|
||||
<pre><code> commits: 252
|
||||
files : 71
|
||||
authors:
|
||||
163 Jake Luer 88.1%
|
||||
16 Veselin Todorov 8.6%
|
||||
3 Jeff Barczewski 1.6%
|
||||
1 Domenic Denicola 0.5%
|
||||
1 John Firebaugh 0.5%
|
||||
1 Vinay Pulim 0.5%</code></pre>
|
||||
192 Jake Luer 76.2%
|
||||
53 Veselin Todorov 21.0%
|
||||
3 Jeff Barczewski 1.2%
|
||||
1 Vinay Pulim 0.4%
|
||||
1 Jo Liss 0.4%
|
||||
1 Domenic Denicola 0.4%
|
||||
1 John Firebaugh 0.4%</code></pre>
|
||||
|
||||
</section>
|
||||
</article>
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -273,4 +273,45 @@ suite('assert', function () {
|
|||
}, "expected \'foo\' to be falsy");
|
||||
});
|
||||
|
||||
test('operator', function() {
|
||||
assert.operator(1, '<', 2);
|
||||
assert.operator(2, '>', 1);
|
||||
assert.operator(1, '==', 1);
|
||||
assert.operator(1, '<=', 1);
|
||||
assert.operator(1, '>=', 1);
|
||||
assert.operator(1, '!=', 2);
|
||||
assert.operator(1, '!==', 2);
|
||||
|
||||
err(function () {
|
||||
assert.operator(1, '=', 2);
|
||||
}, 'Invalid operator "="');
|
||||
|
||||
err(function () {
|
||||
assert.operator(2, '<', 1);
|
||||
}, "expected false to be true");
|
||||
|
||||
err(function () {
|
||||
assert.operator(1, '>', 2);
|
||||
}, "expected false to be true");
|
||||
|
||||
err(function () {
|
||||
assert.operator(1, '==', 2);
|
||||
}, "expected false to be true");
|
||||
|
||||
err(function () {
|
||||
assert.operator(2, '<=', 1);
|
||||
}, "expected false to be true");
|
||||
|
||||
err(function () {
|
||||
assert.operator(1, '>=', 2);
|
||||
}, "expected false to be true");
|
||||
|
||||
err(function () {
|
||||
assert.operator(1, '!=', 1);
|
||||
}, "expected false to be true");
|
||||
|
||||
err(function () {
|
||||
assert.operator(1, '!==', '1');
|
||||
}, "expected false to be true");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -148,6 +148,21 @@ suite('expect', function () {
|
|||
}, "expected 10 to be below 6");
|
||||
});
|
||||
|
||||
test('below(n)', function(){
|
||||
expect(2).to.be.below(5);
|
||||
expect(2).to.be.lessThan(5);
|
||||
expect(2).to.not.be.below(2);
|
||||
expect(2).to.not.be.below(1);
|
||||
|
||||
err(function(){
|
||||
expect(6).to.be.below(5);
|
||||
}, "expected 6 to be below 5");
|
||||
|
||||
err(function(){
|
||||
expect(6).to.not.be.below(10);
|
||||
}, "expected 6 to be above 10");
|
||||
});
|
||||
|
||||
test('match(regexp)', function(){
|
||||
expect('foobar').to.match(/^foo/)
|
||||
expect('foobar').to.not.match(/^bar/)
|
||||
|
@ -200,29 +215,49 @@ suite('expect', function () {
|
|||
});
|
||||
|
||||
test('empty', function(){
|
||||
function FakeArgs() {};
|
||||
FakeArgs.prototype.length = 0;
|
||||
|
||||
expect('').to.be.empty;
|
||||
expect('foo').not.to.be.empty;
|
||||
expect([]).to.be.empty;
|
||||
expect({ length: 0 }).to.be.empty;
|
||||
expect(['foo']).not.to.be.empty;
|
||||
expect(new FakeArgs).to.be.empty;
|
||||
expect({arguments: 0}).not.to.be.empty;
|
||||
expect({}).to.be.empty;
|
||||
expect({foo: 'bar'}).not.to.be.empty;
|
||||
|
||||
err(function(){
|
||||
expect({}).to.be.empty;
|
||||
}, 'expected {} to have a property \'length\'');
|
||||
expect('').not.to.be.empty;
|
||||
}, "expected \'\' not to be empty");
|
||||
|
||||
err(function(){
|
||||
expect([ 'hello', 'world' ]).to.be.empty;
|
||||
}, "expected [ \'hello\', \'world\' ] to be empty");
|
||||
expect('foo').to.be.empty;
|
||||
}, "expected \'foo\' to be empty");
|
||||
|
||||
err(function(){
|
||||
expect([ { hello: 'world' } ]).to.be.empty;
|
||||
}, "expected [ { hello: \'world\' } ] to be empty");
|
||||
expect([]).not.to.be.empty;
|
||||
}, "expected [] not to be empty");
|
||||
|
||||
err(function(){
|
||||
expect('asd').to.be.empty;
|
||||
}, "expected 'asd' to be empty");
|
||||
expect(['foo']).to.be.empty;
|
||||
}, "expected [ \'foo\' ] to be empty");
|
||||
|
||||
err(function(){
|
||||
expect('').to.not.be.empty;
|
||||
}, "expected '' not to be empty");
|
||||
expect(new FakeArgs).not.to.be.empty;
|
||||
}, "expected {} not to be empty");
|
||||
|
||||
err(function(){
|
||||
expect({arguments: 0}).to.be.empty;
|
||||
}, "expected { arguments: 0 } to be empty");
|
||||
|
||||
err(function(){
|
||||
expect({}).not.to.be.empty;
|
||||
}, "expected {} not to be empty");
|
||||
|
||||
err(function(){
|
||||
expect({foo: 'bar'}).to.be.empty;
|
||||
}, "expected { foo: \'bar\' } to be empty");
|
||||
});
|
||||
|
||||
test('property(name)', function(){
|
||||
|
@ -397,6 +432,11 @@ suite('expect', function () {
|
|||
|
||||
expect(badFn).to.throw(/testing/);
|
||||
expect(badFn).to.not.throw(/hello/);
|
||||
expect(badFn).to.throw('testing');
|
||||
expect(badFn).to.not.throw('hello');
|
||||
|
||||
expect(badFn).to.throw(Error, /testing/);
|
||||
expect(badFn).to.throw(Error, 'testing');
|
||||
|
||||
err(function(){
|
||||
expect(goodFn).to.throw();
|
||||
|
@ -433,6 +473,14 @@ suite('expect', function () {
|
|||
err(function () {
|
||||
expect(badFn).to.throw(/hello/);
|
||||
}, "expected [Function] to throw error matching /hello/ but got \'testing\'");
|
||||
|
||||
err(function () {
|
||||
expect(badFn).to.throw(Error, /hello/);
|
||||
}, "expected [Function] to throw error matching /hello/ but got 'testing'");
|
||||
|
||||
err(function () {
|
||||
expect(badFn).to.throw(Error, 'hello');
|
||||
}, "expected [Function] to throw error including 'hello' but got 'testing'");
|
||||
});
|
||||
|
||||
test('respondTo', function(){
|
||||
|
|
|
@ -31,6 +31,7 @@ suite('should', function() {
|
|||
test('assertion', function(){
|
||||
'test'.should.be.a('string');
|
||||
should.equal('foo', 'foo');
|
||||
should.not.equal('foo', 'bar');
|
||||
});
|
||||
|
||||
test('root exist', function () {
|
||||
|
@ -49,9 +50,10 @@ suite('should', function() {
|
|||
});
|
||||
|
||||
test('true', function(){
|
||||
true.should.be.true;
|
||||
(true).should.be.true;
|
||||
false.should.not.be.true;
|
||||
(1).should.not.be.true;
|
||||
(1).should.not.be.true;false
|
||||
false.should.have.been.false;
|
||||
|
||||
err(function(){
|
||||
'test'.should.be.true;
|
||||
|
@ -157,6 +159,21 @@ suite('should', function() {
|
|||
}, "expected 10 to be below 6");
|
||||
});
|
||||
|
||||
test('below(n)', function(){
|
||||
(2).should.be.below(5);
|
||||
(2).should.be.lessThan(5);
|
||||
(2).should.not.be.below(2);
|
||||
(2).should.not.be.below(1);
|
||||
|
||||
err(function(){
|
||||
(6).should.be.below(5);
|
||||
}, "expected 6 to be below 5");
|
||||
|
||||
err(function(){
|
||||
(6).should.not.be.below(10);
|
||||
}, "expected 6 to be above 10");
|
||||
});
|
||||
|
||||
test('match(regexp)', function(){
|
||||
'foobar'.should.match(/^foo/)
|
||||
'foobar'.should.not.match(/^bar/)
|
||||
|
@ -209,21 +226,49 @@ suite('should', function() {
|
|||
});
|
||||
|
||||
test('empty', function(){
|
||||
function FakeArgs() {};
|
||||
FakeArgs.prototype.length = 0;
|
||||
|
||||
''.should.be.empty;
|
||||
[].should.be.empty;
|
||||
({ length: 0 }).should.be.empty;
|
||||
|
||||
err(function(){
|
||||
({}).should.be.empty;
|
||||
}, 'expected {} to have a property \'length\'');
|
||||
|
||||
err(function(){
|
||||
'asd'.should.be.empty;
|
||||
}, "expected 'asd' to be empty");
|
||||
'foo'.should.not.be.empty;
|
||||
([]).should.be.empty;
|
||||
(['foo']).should.not.be.empty;
|
||||
(new FakeArgs).should.be.empty;
|
||||
({arguments: 0}).should.not.be.empty;
|
||||
({}).should.be.empty;
|
||||
({foo: 'bar'}).should.not.be.empty;
|
||||
|
||||
err(function(){
|
||||
''.should.not.be.empty;
|
||||
}, "expected '' not to be empty");
|
||||
}, "expected \'\' not to be empty");
|
||||
|
||||
err(function(){
|
||||
'foo'.should.be.empty;
|
||||
}, "expected \'foo\' to be empty");
|
||||
|
||||
err(function(){
|
||||
([]).should.not.be.empty;
|
||||
}, "expected [] not to be empty");
|
||||
|
||||
err(function(){
|
||||
(['foo']).should.be.empty;
|
||||
}, "expected [ \'foo\' ] to be empty");
|
||||
|
||||
err(function(){
|
||||
(new FakeArgs).should.not.be.empty;
|
||||
}, "expected {} not to be empty");
|
||||
|
||||
err(function(){
|
||||
({arguments: 0}).should.be.empty;
|
||||
}, "expected { arguments: 0 } to be empty");
|
||||
|
||||
err(function(){
|
||||
({}).should.not.be.empty;
|
||||
}, "expected {} not to be empty");
|
||||
|
||||
err(function(){
|
||||
({foo: 'bar'}).should.be.empty;
|
||||
}, "expected { foo: \'bar\' } to be empty");
|
||||
});
|
||||
|
||||
test('property(name)', function(){
|
||||
|
@ -373,7 +418,7 @@ suite('should', function() {
|
|||
test('throw', function () {
|
||||
var goodFn = function () { 1==1; }
|
||||
, badFn = function () { throw new Error('testing'); }
|
||||
, refErrFn = function () { throw new ReferenceError(); };
|
||||
, refErrFn = function () { throw new ReferenceError('hello'); };
|
||||
|
||||
(goodFn).should.not.throw();
|
||||
(goodFn).should.not.throw(Error);
|
||||
|
@ -386,13 +431,19 @@ suite('should', function() {
|
|||
(refErrFn).should.not.throw(TypeError);
|
||||
|
||||
(badFn).should.throw(/testing/);
|
||||
(badFn).should.throw('testing');
|
||||
(badFn).should.not.throw(/hello/);
|
||||
(badFn).should.throw(Error, /testing/);
|
||||
(badFn).should.throw(Error, 'testing');
|
||||
|
||||
should.throw(badFn);
|
||||
should.throw(refErrFn, ReferenceError);
|
||||
should.not.throw(goodFn);
|
||||
should.not.throw(badFn, ReferenceError);
|
||||
|
||||
should.throw(badFn, Error, /testing/);
|
||||
should.throw(badFn, Error, 'testing');
|
||||
|
||||
err(function(){
|
||||
(goodFn).should.throw();
|
||||
}, "expected [Function] to throw an error");
|
||||
|
@ -428,6 +479,14 @@ suite('should', function() {
|
|||
err(function () {
|
||||
(badFn).should.throw(/hello/);
|
||||
}, "expected [Function] to throw error matching /hello/ but got \'testing\'");
|
||||
|
||||
err(function () {
|
||||
(badFn).should.throw(Error, /hello/);
|
||||
}, "expected [Function] to throw error matching /hello/ but got 'testing'");
|
||||
|
||||
err(function () {
|
||||
(badFn).should.throw(Error, 'hello');
|
||||
}, "expected [Function] to throw error including 'hello' but got 'testing'");
|
||||
});
|
||||
|
||||
test('respondTo', function(){
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
var used = [];
|
||||
var exports = module.exports = {};
|
||||
|
||||
exports.version = '0.4.2';
|
||||
exports.version = '0.5.0';
|
||||
|
||||
exports.Assertion = require('./assertion');
|
||||
exports.AssertionError = require('./error');
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"name": "chai",
|
||||
"description": "BDD/TDD assertion library for node.js and the browser. Test framework agnostic.",
|
||||
"keywords": [ "test", "assertion", "assert", "testing" ],
|
||||
"version": "0.4.2",
|
||||
"version": "0.5.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/logicalparadox/chai"
|
||||
|
|
Loading…
Reference in a new issue