2013-09-17 21:22:36 +00:00
|
|
|
describe('expect', function () {
|
2012-11-29 08:18:48 +00:00
|
|
|
var expect = chai.expect;
|
2012-01-02 05:45:06 +00:00
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('chai.version', function() {
|
2012-04-22 20:54:11 +00:00
|
|
|
expect(chai).to.have.property('version');
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('assertion', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
expect('test').to.be.a('string');
|
|
|
|
expect('foo').to.equal('foo');
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('true', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
expect(true).to.be.true;
|
|
|
|
expect(false).to.not.be.true;
|
|
|
|
expect(1).to.not.be.true;
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect('test').to.be.true;
|
|
|
|
}, "expected 'test' to be true")
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('ok', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
expect(true).to.be.ok;
|
|
|
|
expect(false).to.not.be.ok;
|
|
|
|
expect(1).to.be.ok;
|
|
|
|
expect(0).to.not.be.ok;
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect('').to.be.ok;
|
|
|
|
}, "expected '' to be truthy");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect('test').to.not.be.ok;
|
2012-02-27 20:33:24 +00:00
|
|
|
}, "expected 'test' to be falsy");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('false', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
expect(false).to.be.false;
|
|
|
|
expect(true).to.not.be.false;
|
|
|
|
expect(0).to.not.be.false;
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect('').to.be.false;
|
|
|
|
}, "expected '' to be false")
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('null', function(){
|
2012-04-29 06:44:44 +00:00
|
|
|
expect(null).to.be.null;
|
|
|
|
expect(false).to.not.be.null;
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect('').to.be.null;
|
|
|
|
}, "expected '' to be null")
|
|
|
|
});
|
2012-04-29 06:44:57 +00:00
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('undefined', function(){
|
2012-04-29 06:44:57 +00:00
|
|
|
expect(undefined).to.be.undefined;
|
|
|
|
expect(null).to.not.be.undefined;
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect('').to.be.undefined;
|
|
|
|
}, "expected '' to be undefined")
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('exist', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
var foo = 'bar'
|
|
|
|
, bar;
|
|
|
|
expect(foo).to.exist;
|
|
|
|
expect(bar).to.not.exist;
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('arguments', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
var args = (function(){ return arguments; })(1,2,3);
|
|
|
|
expect(args).to.be.arguments;
|
|
|
|
expect([]).to.not.be.arguments;
|
2012-05-29 17:07:00 +00:00
|
|
|
expect(args).to.be.an('arguments').and.be.arguments;
|
|
|
|
expect([]).to.be.an('array').and.not.be.Arguments;
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('.equal()', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
var foo;
|
|
|
|
expect(undefined).to.equal(foo);
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('typeof', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
expect('test').to.be.a('string');
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect('test').to.not.be.a('string');
|
|
|
|
}, "expected 'test' not to be a string");
|
|
|
|
|
2013-02-03 20:12:29 +00:00
|
|
|
(function () {
|
|
|
|
expect(arguments).to.be.an('arguments');
|
|
|
|
})(1, 2);
|
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
expect(5).to.be.a('number');
|
2012-02-25 18:28:40 +00:00
|
|
|
expect(new Number(1)).to.be.a('number');
|
2012-02-25 18:42:49 +00:00
|
|
|
expect(Number(1)).to.be.a('number');
|
2012-02-25 18:33:05 +00:00
|
|
|
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');
|
2012-02-25 18:38:43 +00:00
|
|
|
expect(function() {}).to.be.a('function');
|
2012-12-15 20:08:30 +00:00
|
|
|
expect(null).to.be.a('null');
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(5).to.not.be.a('number', 'blah');
|
|
|
|
}, "blah: expected 5 not to be a number");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('instanceof', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
function Foo(){}
|
|
|
|
expect(new Foo()).to.be.an.instanceof(Foo);
|
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(3).to.an.instanceof(Foo, 'blah');
|
|
|
|
}, "blah: expected 3 to be an instance of Foo");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('within(start, finish)', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
expect(5).to.be.within(5, 10);
|
|
|
|
expect(5).to.be.within(3,6);
|
|
|
|
expect(5).to.be.within(3,5);
|
|
|
|
expect(5).to.not.be.within(1,3);
|
2012-06-24 12:46:44 +00:00
|
|
|
expect('foo').to.have.length.within(2,4);
|
|
|
|
expect([ 1, 2, 3 ]).to.have.length.within(2,4);
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(5).to.not.be.within(4,6, 'blah');
|
|
|
|
}, "blah: expected 5 to not be within 4..6", 'blah');
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(10).to.be.within(50,100, 'blah');
|
|
|
|
}, "blah: expected 10 to be within 50..100");
|
2012-06-24 12:46:44 +00:00
|
|
|
|
|
|
|
err(function () {
|
2012-09-05 18:13:14 +00:00
|
|
|
expect('foo').to.have.length.within(5,7, 'blah');
|
|
|
|
}, "blah: expected \'foo\' to have a length within 5..7");
|
2012-06-24 12:46:44 +00:00
|
|
|
|
|
|
|
err(function () {
|
2012-09-05 18:13:14 +00:00
|
|
|
expect([ 1, 2, 3 ]).to.have.length.within(5,7, 'blah');
|
|
|
|
}, "blah: expected [ 1, 2, 3 ] to have a length within 5..7");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('above(n)', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
expect(5).to.be.above(2);
|
|
|
|
expect(5).to.be.greaterThan(2);
|
|
|
|
expect(5).to.not.be.above(5);
|
|
|
|
expect(5).to.not.be.above(6);
|
2012-06-24 12:46:44 +00:00
|
|
|
expect('foo').to.have.length.above(2);
|
|
|
|
expect([ 1, 2, 3 ]).to.have.length.above(2);
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(5).to.be.above(6, 'blah');
|
|
|
|
}, "blah: expected 5 to be above 6", 'blah');
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(10).to.not.be.above(6, 'blah');
|
2012-11-27 05:02:47 +00:00
|
|
|
}, "blah: expected 10 to be at most 6");
|
2012-06-24 12:46:44 +00:00
|
|
|
|
|
|
|
err(function () {
|
2012-09-05 18:13:14 +00:00
|
|
|
expect('foo').to.have.length.above(4, 'blah');
|
|
|
|
}, "blah: expected \'foo\' to have a length above 4 but got 3");
|
2012-06-24 12:46:44 +00:00
|
|
|
|
|
|
|
err(function () {
|
2012-09-05 18:13:14 +00:00
|
|
|
expect([ 1, 2, 3 ]).to.have.length.above(4, 'blah');
|
|
|
|
}, "blah: expected [ 1, 2, 3 ] to have a length above 4 but got 3");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('least(n)', function(){
|
2012-11-27 05:02:47 +00:00
|
|
|
expect(5).to.be.at.least(2);
|
|
|
|
expect(5).to.be.at.least(5);
|
|
|
|
expect(5).to.not.be.at.least(6);
|
|
|
|
expect('foo').to.have.length.of.at.least(2);
|
|
|
|
expect([ 1, 2, 3 ]).to.have.length.of.at.least(2);
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect(5).to.be.at.least(6, 'blah');
|
|
|
|
}, "blah: expected 5 to be at least 6", 'blah');
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect(10).to.not.be.at.least(6, 'blah');
|
|
|
|
}, "blah: expected 10 to be below 6");
|
|
|
|
|
|
|
|
err(function () {
|
|
|
|
expect('foo').to.have.length.of.at.least(4, 'blah');
|
|
|
|
}, "blah: expected \'foo\' to have a length at least 4 but got 3");
|
|
|
|
|
|
|
|
err(function () {
|
|
|
|
expect([ 1, 2, 3 ]).to.have.length.of.at.least(4, 'blah');
|
|
|
|
}, "blah: expected [ 1, 2, 3 ] to have a length at least 4 but got 3");
|
2013-02-02 04:12:01 +00:00
|
|
|
|
|
|
|
err(function () {
|
|
|
|
expect([ 1, 2, 3, 4 ]).to.not.have.length.of.at.least(4, 'blah');
|
|
|
|
}, "blah: expected [ 1, 2, 3, 4 ] to have a length below 4");
|
2012-11-27 05:02:47 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('below(n)', function(){
|
2012-03-02 00:28:30 +00:00
|
|
|
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);
|
2012-06-24 12:46:44 +00:00
|
|
|
expect('foo').to.have.length.below(4);
|
|
|
|
expect([ 1, 2, 3 ]).to.have.length.below(4);
|
2012-03-02 00:28:30 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(6).to.be.below(5, 'blah');
|
|
|
|
}, "blah: expected 6 to be below 5");
|
2012-03-02 00:28:30 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(6).to.not.be.below(10, 'blah');
|
2012-11-27 05:02:47 +00:00
|
|
|
}, "blah: expected 6 to be at least 10");
|
2012-06-24 12:46:44 +00:00
|
|
|
|
|
|
|
err(function () {
|
2012-09-05 18:13:14 +00:00
|
|
|
expect('foo').to.have.length.below(2, 'blah');
|
|
|
|
}, "blah: expected \'foo\' to have a length below 2 but got 3");
|
2012-06-24 12:46:44 +00:00
|
|
|
|
|
|
|
err(function () {
|
2012-09-05 18:13:14 +00:00
|
|
|
expect([ 1, 2, 3 ]).to.have.length.below(2, 'blah');
|
|
|
|
}, "blah: expected [ 1, 2, 3 ] to have a length below 2 but got 3");
|
2012-03-02 00:28:30 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('most(n)', function(){
|
2012-11-27 05:02:47 +00:00
|
|
|
expect(2).to.be.at.most(5);
|
|
|
|
expect(2).to.be.at.most(2);
|
|
|
|
expect(2).to.not.be.at.most(1);
|
|
|
|
expect(2).to.not.be.at.most(1);
|
|
|
|
expect('foo').to.have.length.of.at.most(4);
|
|
|
|
expect([ 1, 2, 3 ]).to.have.length.of.at.most(4);
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect(6).to.be.at.most(5, 'blah');
|
|
|
|
}, "blah: expected 6 to be at most 5");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect(6).to.not.be.at.most(10, 'blah');
|
|
|
|
}, "blah: expected 6 to be above 10");
|
|
|
|
|
|
|
|
err(function () {
|
|
|
|
expect('foo').to.have.length.of.at.most(2, 'blah');
|
|
|
|
}, "blah: expected \'foo\' to have a length at most 2 but got 3");
|
|
|
|
|
|
|
|
err(function () {
|
|
|
|
expect([ 1, 2, 3 ]).to.have.length.of.at.most(2, 'blah');
|
|
|
|
}, "blah: expected [ 1, 2, 3 ] to have a length at most 2 but got 3");
|
2013-02-02 04:12:01 +00:00
|
|
|
|
|
|
|
err(function () {
|
|
|
|
expect([ 1, 2 ]).to.not.have.length.of.at.most(2, 'blah');
|
|
|
|
}, "blah: expected [ 1, 2 ] to have a length above 2");
|
2012-11-27 05:02:47 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('match(regexp)', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
expect('foobar').to.match(/^foo/)
|
|
|
|
expect('foobar').to.not.match(/^bar/)
|
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect('foobar').to.match(/^bar/i, 'blah')
|
|
|
|
}, "blah: expected 'foobar' to match /^bar/i");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect('foobar').to.not.match(/^foo/i, 'blah')
|
|
|
|
}, "blah: expected 'foobar' not to match /^foo/i");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('length(n)', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
expect('test').to.have.length(4);
|
|
|
|
expect('test').to.not.have.length(3);
|
|
|
|
expect([1,2,3]).to.have.length(3);
|
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(4).to.have.length(3, 'blah');
|
|
|
|
}, 'blah: expected 4 to have a property \'length\'');
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect('asd').to.not.have.length(3, 'blah');
|
|
|
|
}, "blah: expected 'asd' to not have a length of 3");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('eql(val)', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
expect('test').to.eql('test');
|
|
|
|
expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
|
|
|
|
expect(1).to.eql(1);
|
|
|
|
expect('4').to.not.eql(4);
|
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(4).to.eql(3, 'blah');
|
|
|
|
}, 'blah: expected 4 to deeply equal 3');
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2012-10-01 18:47:21 +00:00
|
|
|
if ('undefined' !== typeof Buffer) {
|
2013-09-17 21:22:36 +00:00
|
|
|
it('Buffer eql()', function () {
|
2012-10-01 18:47:21 +00:00
|
|
|
expect(new Buffer([ 1 ])).to.eql(new Buffer([ 1 ]));
|
|
|
|
|
|
|
|
err(function () {
|
|
|
|
expect(new Buffer([ 0 ])).to.eql(new Buffer([ 1 ]));
|
|
|
|
}, 'expected <Buffer 00> to deeply equal <Buffer 01>');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('equal(val)', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
expect('test').to.equal('test');
|
|
|
|
expect(1).to.equal(1);
|
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(4).to.equal(3, 'blah');
|
|
|
|
}, 'blah: expected 4 to equal 3');
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect('4').to.equal(4, 'blah');
|
|
|
|
}, "blah: expected '4' to equal 4");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('deep.equal(val)', function(){
|
2012-05-17 01:14:52 +00:00
|
|
|
expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });
|
2012-05-27 21:31:06 +00:00
|
|
|
expect({ foo: 'bar' }).not.to.deep.equal({ foo: 'baz' });
|
2012-05-17 01:14:52 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('deep.equal(/regexp/)', function(){
|
2013-06-04 22:11:28 +00:00
|
|
|
expect(/a/).to.deep.equal(/a/);
|
|
|
|
expect(/a/).not.to.deep.equal(/b/);
|
2013-06-05 21:53:34 +00:00
|
|
|
expect(/a/).not.to.deep.equal({});
|
2013-06-05 20:26:42 +00:00
|
|
|
expect(/a/g).to.deep.equal(/a/g);
|
|
|
|
expect(/a/g).not.to.deep.equal(/b/g);
|
|
|
|
expect(/a/i).to.deep.equal(/a/i);
|
|
|
|
expect(/a/i).not.to.deep.equal(/b/i);
|
|
|
|
expect(/a/m).to.deep.equal(/a/m);
|
|
|
|
expect(/a/m).not.to.deep.equal(/b/m);
|
2013-06-04 22:11:28 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('deep.equal(Date)', function(){
|
2013-06-05 21:53:34 +00:00
|
|
|
var a = new Date(1, 2, 3)
|
|
|
|
, b = new Date(4, 5, 6);
|
|
|
|
expect(a).to.deep.equal(a);
|
|
|
|
expect(a).not.to.deep.equal(b);
|
|
|
|
expect(a).not.to.deep.equal({});
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('empty', function(){
|
2012-02-29 19:51:42 +00:00
|
|
|
function FakeArgs() {};
|
|
|
|
FakeArgs.prototype.length = 0;
|
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
expect('').to.be.empty;
|
2012-03-07 16:01:18 +00:00
|
|
|
expect('foo').not.to.be.empty;
|
2012-01-02 05:45:06 +00:00
|
|
|
expect([]).to.be.empty;
|
2012-03-07 16:01:18 +00:00
|
|
|
expect(['foo']).not.to.be.empty;
|
2012-02-29 19:51:42 +00:00
|
|
|
expect(new FakeArgs).to.be.empty;
|
2012-03-07 16:01:18 +00:00
|
|
|
expect({arguments: 0}).not.to.be.empty;
|
2012-02-29 19:51:42 +00:00
|
|
|
expect({}).to.be.empty;
|
2012-03-07 16:01:18 +00:00
|
|
|
expect({foo: 'bar'}).not.to.be.empty;
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-03-07 16:01:18 +00:00
|
|
|
expect('').not.to.be.empty;
|
|
|
|
}, "expected \'\' not to be empty");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-03-07 16:01:18 +00:00
|
|
|
expect('foo').to.be.empty;
|
|
|
|
}, "expected \'foo\' to be empty");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-03-07 16:01:18 +00:00
|
|
|
expect([]).not.to.be.empty;
|
|
|
|
}, "expected [] not to be empty");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-03-07 16:01:18 +00:00
|
|
|
expect(['foo']).to.be.empty;
|
|
|
|
}, "expected [ \'foo\' ] to be empty");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect(new FakeArgs).not.to.be.empty;
|
2012-12-30 11:25:17 +00:00
|
|
|
}, "expected { length: 0 } not to be empty");
|
2012-03-07 16:01:18 +00:00
|
|
|
|
|
|
|
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");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('property(name)', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
expect('test').to.have.property('length');
|
|
|
|
expect(4).to.not.have.property('length');
|
|
|
|
|
2012-05-17 01:14:52 +00:00
|
|
|
expect({ 'foo.bar': 'baz' })
|
2012-05-06 11:22:29 +00:00
|
|
|
.to.have.property('foo.bar');
|
2012-05-17 01:14:52 +00:00
|
|
|
expect({ foo: { bar: 'baz' } })
|
|
|
|
.to.not.have.property('foo.bar');
|
2012-05-06 11:22:29 +00:00
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
err(function(){
|
|
|
|
expect('asd').to.have.property('foo');
|
|
|
|
}, "expected 'asd' to have a property 'foo'");
|
2012-05-17 01:14:52 +00:00
|
|
|
err(function(){
|
|
|
|
expect({ foo: { bar: 'baz' } })
|
|
|
|
.to.have.property('foo.bar');
|
|
|
|
}, "expected { foo: { bar: 'baz' } } to have a property 'foo.bar'");
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('deep.property(name)', function(){
|
2012-05-17 01:14:52 +00:00
|
|
|
expect({ 'foo.bar': 'baz'})
|
|
|
|
.to.not.have.deep.property('foo.bar');
|
|
|
|
expect({ foo: { bar: 'baz' } })
|
|
|
|
.to.have.deep.property('foo.bar');
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect({ 'foo.bar': 'baz' })
|
|
|
|
.to.have.deep.property('foo.bar');
|
|
|
|
}, "expected { 'foo.bar': 'baz' } to have a deep property 'foo.bar'");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('property(name, val)', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
expect('test').to.have.property('length', 4);
|
|
|
|
expect('asd').to.have.property('constructor', String);
|
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect('asd').to.have.property('length', 4, 'blah');
|
|
|
|
}, "blah: expected 'asd' to have a property 'length' of 4, but got 3");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect('asd').to.not.have.property('length', 3, 'blah');
|
|
|
|
}, "blah: expected 'asd' to not have a property 'length' of 3");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect('asd').to.not.have.property('foo', 3, 'blah');
|
|
|
|
}, "blah: 'asd' has no property 'foo'");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect('asd').to.have.property('constructor', Number, 'blah');
|
|
|
|
}, "blah: expected 'asd' to have a property 'constructor' of [Function: Number], but got [Function: String]");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('deep.property(name, val)', function(){
|
2012-05-17 01:14:52 +00:00
|
|
|
expect({ foo: { bar: 'baz' } })
|
|
|
|
.to.have.deep.property('foo.bar', 'baz');
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect({ foo: { bar: 'baz' } })
|
2012-09-05 18:13:14 +00:00
|
|
|
.to.have.deep.property('foo.bar', 'quux', 'blah');
|
|
|
|
}, "blah: expected { foo: { bar: 'baz' } } to have a deep property 'foo.bar' of 'quux', but got 'baz'");
|
2012-05-17 01:14:52 +00:00
|
|
|
err(function(){
|
|
|
|
expect({ foo: { bar: 'baz' } })
|
2012-09-05 18:13:14 +00:00
|
|
|
.to.not.have.deep.property('foo.bar', 'baz', 'blah');
|
|
|
|
}, "blah: expected { foo: { bar: 'baz' } } to not have a deep property 'foo.bar' of 'baz'");
|
2012-05-17 01:14:52 +00:00
|
|
|
err(function(){
|
|
|
|
expect({ foo: 5 })
|
2012-09-05 18:13:14 +00:00
|
|
|
.to.not.have.deep.property('foo.bar', 'baz', 'blah');
|
|
|
|
}, "blah: { foo: 5 } has no deep property 'foo.bar'");
|
2012-05-17 01:14:52 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('ownProperty(name)', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
expect('test').to.have.ownProperty('length');
|
|
|
|
expect('test').to.haveOwnProperty('length');
|
|
|
|
expect({ length: 12 }).to.have.ownProperty('length');
|
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect({ length: 12 }).to.not.have.ownProperty('length', 'blah');
|
|
|
|
}, "blah: expected { length: 12 } to not have own property 'length'");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('string()', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
expect('foobar').to.have.string('bar');
|
|
|
|
expect('foobar').to.have.string('foo');
|
|
|
|
expect('foobar').to.not.have.string('baz');
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect(3).to.have.string('baz');
|
|
|
|
}, "expected 3 to be a string");
|
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect('foobar').to.have.string('baz', 'blah');
|
|
|
|
}, "blah: expected 'foobar' to contain 'baz'");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect('foobar').to.not.have.string('bar', 'blah');
|
|
|
|
}, "blah: expected 'foobar' to not contain 'bar'");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('include()', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
expect(['foo', 'bar']).to.include('foo');
|
|
|
|
expect(['foo', 'bar']).to.include('foo');
|
|
|
|
expect(['foo', 'bar']).to.include('bar');
|
|
|
|
expect([1,2]).to.include(1);
|
|
|
|
expect(['foo', 'bar']).to.not.include('baz');
|
|
|
|
expect(['foo', 'bar']).to.not.include(1);
|
2014-01-05 01:10:14 +00:00
|
|
|
expect({a:1,b:2}).to.include({b:2});
|
|
|
|
expect({a:1,b:2}).to.not.include({b:3});
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(['foo']).to.include('bar', 'blah');
|
|
|
|
}, "blah: expected [ 'foo' ] to include 'bar'");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(['bar', 'foo']).to.not.include('foo', 'blah');
|
|
|
|
}, "blah: expected [ 'bar', 'foo' ] to not include 'foo'");
|
2014-01-05 01:10:14 +00:00
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect({a:1}).to.include({b:2});
|
|
|
|
}, "expected { a: 1 } to have a property 'b'");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('keys(array)', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
expect({ foo: 1 }).to.have.keys(['foo']);
|
|
|
|
expect({ foo: 1, bar: 2 }).to.have.keys(['foo', 'bar']);
|
|
|
|
expect({ foo: 1, bar: 2 }).to.have.keys('foo', 'bar');
|
|
|
|
expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');
|
|
|
|
expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('bar', 'foo');
|
|
|
|
expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('baz');
|
|
|
|
|
|
|
|
expect({ foo: 1, bar: 2 }).to.contain.keys('foo');
|
|
|
|
expect({ foo: 1, bar: 2 }).to.contain.keys('bar', 'foo');
|
|
|
|
expect({ foo: 1, bar: 2 }).to.contain.keys(['foo']);
|
|
|
|
expect({ foo: 1, bar: 2 }).to.contain.keys(['bar']);
|
|
|
|
expect({ foo: 1, bar: 2 }).to.contain.keys(['bar', 'foo']);
|
|
|
|
|
|
|
|
expect({ foo: 1, bar: 2 }).to.not.have.keys('baz');
|
|
|
|
expect({ foo: 1, bar: 2 }).to.not.have.keys('foo', 'baz');
|
|
|
|
expect({ foo: 1, bar: 2 }).to.not.contain.keys('baz');
|
|
|
|
expect({ foo: 1, bar: 2 }).to.not.contain.keys('foo', 'baz');
|
|
|
|
expect({ foo: 1, bar: 2 }).to.not.contain.keys('baz', 'foo');
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect({ foo: 1 }).to.have.keys();
|
|
|
|
}, "keys required");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect({ foo: 1 }).to.have.keys([]);
|
|
|
|
}, "keys required");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect({ foo: 1 }).to.not.have.keys([]);
|
|
|
|
}, "keys required");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect({ foo: 1 }).to.contain.keys([]);
|
|
|
|
}, "keys required");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect({ foo: 1 }).to.have.keys(['bar']);
|
|
|
|
}, "expected { foo: 1 } to have key 'bar'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect({ foo: 1 }).to.have.keys(['bar', 'baz']);
|
|
|
|
}, "expected { foo: 1 } to have keys 'bar', and 'baz'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect({ foo: 1 }).to.have.keys(['foo', 'bar', 'baz']);
|
|
|
|
}, "expected { foo: 1 } to have keys 'foo', 'bar', and 'baz'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect({ foo: 1 }).to.not.have.keys(['foo']);
|
|
|
|
}, "expected { foo: 1 } to not have key 'foo'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect({ foo: 1 }).to.not.have.keys(['foo']);
|
|
|
|
}, "expected { foo: 1 } to not have key 'foo'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect({ foo: 1, bar: 2 }).to.not.have.keys(['foo', 'bar']);
|
|
|
|
}, "expected { foo: 1, bar: 2 } to not have keys 'foo', and 'bar'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect({ foo: 1 }).to.not.contain.keys(['foo']);
|
|
|
|
}, "expected { foo: 1 } to not contain key 'foo'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect({ foo: 1 }).to.contain.keys('foo', 'bar');
|
|
|
|
}, "expected { foo: 1 } to contain keys 'foo', and 'bar'");
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('chaining', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
var tea = { name: 'chai', extras: ['milk', 'sugar', 'smile'] };
|
|
|
|
expect(tea).to.have.property('extras').with.lengthOf(3);
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect(tea).to.have.property('extras').with.lengthOf(4);
|
|
|
|
}, "expected [ 'milk', 'sugar', 'smile' ] to have a length of 4 but got 3");
|
|
|
|
|
|
|
|
expect(tea).to.be.a('object').and.have.property('name', 'chai');
|
2013-12-18 12:51:54 +00:00
|
|
|
|
|
|
|
var badFn = function () { throw new Error('testing'); };
|
|
|
|
|
|
|
|
expect(badFn).to.throw(Error).with.property('message', 'testing');
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('throw', function () {
|
2012-04-06 21:57:54 +00:00
|
|
|
// See GH-45: some poorly-constructed custom errors don't have useful names
|
|
|
|
// on either their constructor or their constructor prototype, but instead
|
|
|
|
// only set the name inside the constructor itself.
|
|
|
|
var PoorlyConstructedError = function () {
|
|
|
|
this.name = 'PoorlyConstructedError';
|
|
|
|
};
|
|
|
|
PoorlyConstructedError.prototype = Object.create(Error.prototype);
|
|
|
|
|
2013-10-23 21:48:48 +00:00
|
|
|
function CustomError(message) {
|
|
|
|
this.name = 'CustomError';
|
|
|
|
this.message = message;
|
|
|
|
}
|
|
|
|
CustomError.prototype = Error.prototype;
|
|
|
|
|
2012-04-06 22:19:28 +00:00
|
|
|
var specificError = new RangeError('boo');
|
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
var goodFn = function () { 1==1; }
|
|
|
|
, badFn = function () { throw new Error('testing'); }
|
2012-04-06 21:57:54 +00:00
|
|
|
, refErrFn = function () { throw new ReferenceError('hello'); }
|
2012-04-06 22:19:28 +00:00
|
|
|
, ickyErrFn = function () { throw new PoorlyConstructedError(); }
|
2013-10-23 21:48:48 +00:00
|
|
|
, specificErrFn = function () { throw specificError; }
|
|
|
|
, customErrFn = function() { throw new CustomError('foo'); };
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
expect(goodFn).to.not.throw();
|
|
|
|
expect(goodFn).to.not.throw(Error);
|
2012-04-06 22:19:28 +00:00
|
|
|
expect(goodFn).to.not.throw(specificError);
|
2012-01-02 05:45:06 +00:00
|
|
|
expect(badFn).to.throw();
|
|
|
|
expect(badFn).to.throw(Error);
|
|
|
|
expect(badFn).to.not.throw(ReferenceError);
|
2012-04-06 22:19:28 +00:00
|
|
|
expect(badFn).to.not.throw(specificError);
|
2012-01-02 05:45:06 +00:00
|
|
|
expect(refErrFn).to.throw();
|
|
|
|
expect(refErrFn).to.throw(ReferenceError);
|
2012-04-06 21:39:08 +00:00
|
|
|
expect(refErrFn).to.throw(Error);
|
2012-01-02 05:45:06 +00:00
|
|
|
expect(refErrFn).to.not.throw(TypeError);
|
2012-04-06 22:19:28 +00:00
|
|
|
expect(refErrFn).to.not.throw(specificError);
|
2012-04-06 21:57:54 +00:00
|
|
|
expect(ickyErrFn).to.throw();
|
|
|
|
expect(ickyErrFn).to.throw(PoorlyConstructedError);
|
|
|
|
expect(ickyErrFn).to.throw(Error);
|
2012-04-06 22:19:28 +00:00
|
|
|
expect(ickyErrFn).to.not.throw(specificError);
|
|
|
|
expect(specificErrFn).to.throw(specificError);
|
2012-01-02 05:45:06 +00:00
|
|
|
|
2012-02-07 21:39:08 +00:00
|
|
|
expect(badFn).to.throw(/testing/);
|
|
|
|
expect(badFn).to.not.throw(/hello/);
|
2012-03-07 16:37:23 +00:00
|
|
|
expect(badFn).to.throw('testing');
|
|
|
|
expect(badFn).to.not.throw('hello');
|
|
|
|
|
|
|
|
expect(badFn).to.throw(Error, /testing/);
|
|
|
|
expect(badFn).to.throw(Error, 'testing');
|
2012-02-07 21:39:08 +00:00
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
err(function(){
|
|
|
|
expect(goodFn).to.throw();
|
|
|
|
}, "expected [Function] to throw an error");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect(goodFn).to.throw(ReferenceError);
|
|
|
|
}, "expected [Function] to throw ReferenceError");
|
|
|
|
|
2012-04-06 22:19:28 +00:00
|
|
|
err(function(){
|
|
|
|
expect(goodFn).to.throw(specificError);
|
2013-10-23 21:06:39 +00:00
|
|
|
}, "expected [Function] to throw 'RangeError: boo'");
|
2012-04-06 22:19:28 +00:00
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
err(function(){
|
|
|
|
expect(badFn).to.not.throw();
|
2013-10-23 21:06:39 +00:00
|
|
|
}, "expected [Function] to not throw an error but 'Error: testing' was thrown");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect(badFn).to.throw(ReferenceError);
|
2013-10-23 21:06:39 +00:00
|
|
|
}, "expected [Function] to throw 'ReferenceError' but 'Error: testing' was thrown");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
2012-04-06 22:19:28 +00:00
|
|
|
err(function(){
|
|
|
|
expect(badFn).to.throw(specificError);
|
2013-10-23 21:06:39 +00:00
|
|
|
}, "expected [Function] to throw 'RangeError: boo' but 'Error: testing' was thrown");
|
2012-04-06 22:19:28 +00:00
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
err(function(){
|
|
|
|
expect(badFn).to.not.throw(Error);
|
2013-10-23 21:06:39 +00:00
|
|
|
}, "expected [Function] to not throw 'Error' but 'Error: testing' was thrown");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect(refErrFn).to.not.throw(ReferenceError);
|
2013-10-23 21:06:39 +00:00
|
|
|
}, "expected [Function] to not throw 'ReferenceError' but 'ReferenceError: hello' was thrown");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
2012-04-06 21:57:54 +00:00
|
|
|
err(function(){
|
|
|
|
expect(badFn).to.throw(PoorlyConstructedError);
|
2013-10-23 21:06:39 +00:00
|
|
|
}, "expected [Function] to throw 'PoorlyConstructedError' but 'Error: testing' was thrown");
|
2012-04-06 21:57:54 +00:00
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect(ickyErrFn).to.not.throw(PoorlyConstructedError);
|
2013-02-03 23:03:40 +00:00
|
|
|
}, /^(expected \[Function\] to not throw 'PoorlyConstructedError' but)(.*)(PoorlyConstructedError|\{ Object \()(.*)(was thrown)$/);
|
2012-04-06 21:57:54 +00:00
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect(ickyErrFn).to.throw(ReferenceError);
|
2013-02-03 23:03:40 +00:00
|
|
|
}, /^(expected \[Function\] to throw 'ReferenceError' but)(.*)(PoorlyConstructedError|\{ Object \()(.*)(was thrown)$/);
|
2012-04-06 21:57:54 +00:00
|
|
|
|
2012-04-06 22:19:28 +00:00
|
|
|
err(function(){
|
|
|
|
expect(specificErrFn).to.throw(new ReferenceError('eek'));
|
2013-10-23 21:06:39 +00:00
|
|
|
}, "expected [Function] to throw 'ReferenceError: eek' but 'RangeError: boo' was thrown");
|
2012-04-06 22:19:28 +00:00
|
|
|
|
|
|
|
err(function(){
|
|
|
|
expect(specificErrFn).to.not.throw(specificError);
|
2013-10-23 21:06:39 +00:00
|
|
|
}, "expected [Function] to not throw 'RangeError: boo'");
|
2012-04-06 22:19:28 +00:00
|
|
|
|
2012-02-07 21:39:08 +00:00
|
|
|
err(function (){
|
|
|
|
expect(badFn).to.not.throw(/testing/);
|
|
|
|
}, "expected [Function] to throw error not matching /testing/");
|
|
|
|
|
|
|
|
err(function () {
|
|
|
|
expect(badFn).to.throw(/hello/);
|
2013-02-03 23:03:40 +00:00
|
|
|
}, "expected [Function] to throw error matching /hello/ but got 'testing'");
|
2012-03-07 16:37:23 +00:00
|
|
|
|
|
|
|
err(function () {
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(badFn).to.throw(Error, /hello/, 'blah');
|
|
|
|
}, "blah: expected [Function] to throw error matching /hello/ but got 'testing'");
|
2012-03-07 16:37:23 +00:00
|
|
|
|
|
|
|
err(function () {
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(badFn).to.throw(Error, 'hello', 'blah');
|
|
|
|
}, "blah: expected [Function] to throw error including 'hello' but got 'testing'");
|
2013-10-23 21:48:48 +00:00
|
|
|
|
|
|
|
err(function () {
|
|
|
|
(customErrFn).should.not.throw();
|
|
|
|
}, "expected [Function] to not throw an error but 'CustomError: foo' was thrown");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('respondTo', function(){
|
2012-02-24 19:53:15 +00:00
|
|
|
function Foo(){};
|
|
|
|
Foo.prototype.bar = function(){};
|
2012-06-02 16:41:54 +00:00
|
|
|
Foo.func = function() {};
|
2012-02-24 19:53:15 +00:00
|
|
|
|
|
|
|
var bar = {};
|
|
|
|
bar.foo = function(){};
|
|
|
|
|
|
|
|
expect(Foo).to.respondTo('bar');
|
|
|
|
expect(Foo).to.not.respondTo('foo');
|
2012-06-02 16:41:54 +00:00
|
|
|
expect(Foo).itself.to.respondTo('func');
|
|
|
|
expect(Foo).itself.not.to.respondTo('bar');
|
2012-02-24 19:53:15 +00:00
|
|
|
|
|
|
|
expect(bar).to.respondTo('foo');
|
|
|
|
|
|
|
|
err(function(){
|
2013-02-03 23:03:40 +00:00
|
|
|
expect(Foo).to.respondTo('baz', 'constructor');
|
|
|
|
}, /^(constructor: expected)(.*)(\[Function: Foo\])(.*)(to respond to \'baz\')$/);
|
2012-02-24 19:53:15 +00:00
|
|
|
|
|
|
|
err(function(){
|
2013-02-03 23:03:40 +00:00
|
|
|
expect(bar).to.respondTo('baz', 'object');
|
|
|
|
}, /^(object: expected)(.*)(\{ foo: \[Function\] \}|\{ Object \()(.*)(to respond to \'baz\')$/);
|
2012-02-24 19:53:15 +00:00
|
|
|
});
|
2012-02-24 20:30:20 +00:00
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('satisfy', function(){
|
2013-09-18 03:12:16 +00:00
|
|
|
var matcher = function (num) {
|
2012-02-24 20:30:20 +00:00
|
|
|
return num === 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(1).to.satisfy(matcher);
|
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(2).to.satisfy(matcher, 'blah');
|
2013-09-18 03:12:16 +00:00
|
|
|
}, "blah: expected 2 to satisfy [Function]");
|
2012-02-24 20:30:20 +00:00
|
|
|
});
|
2012-02-24 22:00:03 +00:00
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('closeTo', function(){
|
2012-02-24 22:00:03 +00:00
|
|
|
expect(1.5).to.be.closeTo(1.0, 0.5);
|
2012-06-26 11:41:15 +00:00
|
|
|
expect(10).to.be.closeTo(20, 20);
|
|
|
|
expect(-10).to.be.closeTo(20, 30);
|
2012-02-24 22:00:03 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(2).to.be.closeTo(1.0, 0.5, 'blah');
|
|
|
|
}, "blah: expected 2 to be close to 1 +/- 0.5");
|
2012-06-26 11:41:15 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 18:13:14 +00:00
|
|
|
expect(-10).to.be.closeTo(20, 29, 'blah');
|
|
|
|
}, "blah: expected -10 to be close to 20 +/- 29");
|
2012-02-24 22:00:03 +00:00
|
|
|
});
|
2013-04-14 19:40:32 +00:00
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('include.members', function() {
|
2013-04-14 23:07:12 +00:00
|
|
|
expect([1, 2, 3]).to.include.members([]);
|
|
|
|
expect([1, 2, 3]).to.include.members([3, 2]);
|
|
|
|
expect([1, 2, 3]).to.not.include.members([8, 4]);
|
|
|
|
expect([1, 2, 3]).to.not.include.members([1, 2, 3, 4]);
|
2013-04-14 19:40:32 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('same.members', function() {
|
2013-04-14 23:07:12 +00:00
|
|
|
expect([5, 4]).to.have.same.members([4, 5]);
|
|
|
|
expect([5, 4]).to.have.same.members([5, 4]);
|
|
|
|
expect([5, 4]).to.not.have.same.members([]);
|
|
|
|
expect([5, 4]).to.not.have.same.members([6, 3]);
|
|
|
|
expect([5, 4]).to.not.have.same.members([5, 4, 2]);
|
2013-04-14 19:40:32 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('members', function() {
|
|
|
|
expect([5, 4]).members([4, 5]);
|
|
|
|
expect([5, 4]).members([5, 4]);
|
|
|
|
expect([5, 4]).not.members([]);
|
|
|
|
expect([5, 4]).not.members([6, 3]);
|
|
|
|
expect([5, 4]).not.members([5, 4, 2]);
|
2013-04-23 15:12:23 +00:00
|
|
|
})
|
|
|
|
|
2012-01-21 23:38:18 +00:00
|
|
|
});
|