2013-09-17 21:22:36 +00:00
|
|
|
describe('should', function() {
|
2012-08-25 02:33:47 +00:00
|
|
|
var should = chai.Should();
|
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
|
|
|
'test'.should.be.a('string');
|
|
|
|
should.equal('foo', 'foo');
|
2012-03-02 00:28:30 +00:00
|
|
|
should.not.equal('foo', 'bar');
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2016-05-07 02:27:35 +00:00
|
|
|
it('no-op chains', function() {
|
|
|
|
function test(chain) {
|
|
|
|
// tests that chain exists
|
|
|
|
((1).should[chain]).should.not.undefined;
|
|
|
|
|
|
|
|
// tests methods
|
|
|
|
(1).should[chain].equal(1);
|
|
|
|
|
|
|
|
// tests properties that assert
|
|
|
|
(false).should[chain].false;
|
|
|
|
|
|
|
|
// tests not
|
|
|
|
(false).should[chain].not.true;
|
|
|
|
|
|
|
|
// tests chainable methods
|
|
|
|
[1, 2, 3].should[chain].contains(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
[ 'to', 'be', 'been'
|
|
|
|
, 'is', 'and', 'has', 'have'
|
|
|
|
, 'with', 'that', 'which', 'at'
|
2016-05-06 23:26:35 +00:00
|
|
|
, 'of', 'same', 'but', 'does' ].forEach(test);
|
2016-05-07 02:27:35 +00:00
|
|
|
});
|
|
|
|
|
2015-01-29 20:38:53 +00:00
|
|
|
it('fail', function () {
|
2015-01-29 20:48:19 +00:00
|
|
|
err(function() {
|
2015-01-29 20:38:53 +00:00
|
|
|
should.fail(0, 1, 'this has failed');
|
2015-01-29 20:48:19 +00:00
|
|
|
}, 'this has failed');
|
2015-01-29 20:38:53 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('root exist', function () {
|
2012-01-02 05:48:43 +00:00
|
|
|
var foo = 'foo'
|
|
|
|
, bar = undefined;
|
|
|
|
should.exist(foo);
|
|
|
|
should.not.exist(bar);
|
|
|
|
|
|
|
|
err(function () {
|
2012-09-05 06:09:40 +00:00
|
|
|
should.exist(bar, 'blah');
|
|
|
|
}, "blah: expected undefined to exist");
|
2012-01-02 05:48:43 +00:00
|
|
|
|
|
|
|
err(function () {
|
2012-09-05 06:09:40 +00:00
|
|
|
should.not.exist(foo, 'blah');
|
|
|
|
}, "blah: expected 'foo' to not exist")
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('root equal', function () {
|
2012-09-05 06:09:40 +00:00
|
|
|
var value1 = 'value'
|
|
|
|
, value2 = 'value'
|
|
|
|
, foo = 'foo';
|
|
|
|
should.equal(value1, value2);
|
|
|
|
should.not.equal(value1, foo);
|
|
|
|
|
|
|
|
err(function () {
|
|
|
|
should.equal(value1, foo, 'blah');
|
|
|
|
}, "blah: expected 'value' to equal 'foo'");
|
|
|
|
|
|
|
|
err(function () {
|
|
|
|
should.not.equal(value1, value2, 'blah');
|
|
|
|
}, "blah: expected 'value' to not equal 'value'")
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('root Throw', function () {
|
2012-09-05 06:09:40 +00:00
|
|
|
should.Throw(function() { throw new Error('error!') }, Error, 'error!');
|
|
|
|
should.not.Throw(function () { });
|
|
|
|
|
|
|
|
err(function () {
|
|
|
|
should.Throw(function () { throw new Error('error!') }, Error, 'needed user!', 'blah');
|
|
|
|
}, "blah: expected [Function] to throw error including 'needed user!' but got 'error!'");
|
|
|
|
|
|
|
|
err(function () {
|
|
|
|
should.not.Throw(function () { throw new Error('error!') }, Error, 'error!', 'blah');
|
2013-10-23 21:06:39 +00:00
|
|
|
}, "blah: expected [Function] to not throw 'Error' but 'Error: error!' was thrown");
|
2012-01-02 05:48:43 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('true', function(){
|
2012-03-02 00:28:30 +00:00
|
|
|
(true).should.be.true;
|
2012-01-02 05:45:06 +00:00
|
|
|
false.should.not.be.true;
|
2012-03-02 00:29:55 +00:00
|
|
|
(1).should.not.be.true;false
|
|
|
|
false.should.have.been.false;
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
|
|
|
'test'.should.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
|
|
|
true.should.be.ok;
|
|
|
|
false.should.not.be.ok;
|
|
|
|
(1).should.be.ok;
|
|
|
|
(0).should.not.be.ok;
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
''.should.be.ok;
|
|
|
|
}, "expected '' to be truthy");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
'test'.should.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
|
|
|
false.should.be.false;
|
|
|
|
true.should.not.be.false;
|
|
|
|
(0).should.not.be.false;
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
''.should.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
|
|
|
(0).should.not.be.null;
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
''.should.be.null;
|
|
|
|
}, "expected '' to be null")
|
|
|
|
});
|
2012-04-29 06:44:57 +00:00
|
|
|
|
2015-07-16 17:18:54 +00:00
|
|
|
it('NaN', function(){
|
|
|
|
'foo'.should.be.NaN;
|
|
|
|
(4).should.not.be.NaN;
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
(4).should.be.NaN;
|
|
|
|
}, "expected 4 to be NaN")
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('undefined', function(){
|
2012-04-29 06:44:57 +00:00
|
|
|
(0).should.not.be.undefined;
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
''.should.be.undefined;
|
|
|
|
}, "expected '' to be undefined")
|
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
args.should.be.arguments;
|
|
|
|
[].should.not.be.arguments;
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('.equal()', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
var foo;
|
|
|
|
should.equal(undefined, foo);
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('typeof', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
'test'.should.be.a('string');
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
'test'.should.not.be.a('string');
|
|
|
|
}, "expected 'test' not to be a string");
|
|
|
|
|
2012-02-25 18:42:49 +00:00
|
|
|
(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');
|
|
|
|
|
2016-04-08 00:15:29 +00:00
|
|
|
if (typeof Symbol === 'function') {
|
|
|
|
Symbol().should.be.a('symbol');
|
|
|
|
}
|
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
(5).should.be.a('number');
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
(5).should.not.be.a('number');
|
|
|
|
}, "expected 5 not to be a number");
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('instanceof', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
function Foo(){}
|
|
|
|
new Foo().should.be.an.instanceof(Foo);
|
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
(3).should.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
|
|
|
(5).should.be.within(5, 10);
|
|
|
|
(5).should.be.within(3,6);
|
|
|
|
(5).should.be.within(3,5);
|
|
|
|
(5).should.not.be.within(1,3);
|
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
(5).should.not.be.within(4,6, 'blah');
|
|
|
|
}, "blah: expected 5 to not be within 4..6");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
(10).should.be.within(50,100, 'blah');
|
|
|
|
}, "blah: expected 10 to be within 50..100");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
({ foo: 1 }).should.have.length.within(50,100, 'blah');
|
|
|
|
}, "blah: expected { foo: 1 } to have a property 'length'");
|
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
|
|
|
(5).should.be.above(2);
|
|
|
|
(5).should.be.greaterThan(2);
|
|
|
|
(5).should.not.be.above(5);
|
|
|
|
(5).should.not.be.above(6);
|
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
(5).should.be.above(6, 'blah');
|
|
|
|
}, "blah: expected 5 to be above 6");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
(10).should.not.be.above(6, 'blah');
|
2012-11-27 05:02:47 +00:00
|
|
|
}, "blah: expected 10 to be at most 6");
|
2012-09-05 06:09:40 +00:00
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({foo: 1}).should.have.length.above(3, 'blah');
|
|
|
|
}, "blah: expected { foo: 1 } to have a property 'length'");
|
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
|
|
|
(5).should.be.at.least(5);
|
|
|
|
(5).should.not.be.at.least(6);
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
(5).should.be.at.least(6, 'blah');
|
|
|
|
}, "blah: expected 5 to be at least 6");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
(10).should.not.be.at.least(6, 'blah');
|
|
|
|
}, "blah: expected 10 to be below 6");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({foo: 1}).should.have.length.of.at.least(3, 'blah');
|
|
|
|
}, "blah: expected { foo: 1 } to have a property 'length'");
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('below(n)', function(){
|
2012-03-02 00:28:30 +00:00
|
|
|
(2).should.be.below(5);
|
|
|
|
(2).should.be.lessThan(5);
|
|
|
|
(2).should.not.be.below(2);
|
|
|
|
(2).should.not.be.below(1);
|
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
(6).should.be.below(5, 'blah');
|
|
|
|
}, "blah: expected 6 to be below 5");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
(6).should.not.be.below(10, 'blah');
|
2012-11-27 05:02:47 +00:00
|
|
|
}, "blah: expected 6 to be at least 10");
|
2012-03-02 00:28:30 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
({foo: 1}).should.have.length.below(3, 'blah');
|
|
|
|
}, "blah: expected { foo: 1 } to have a property 'length'");
|
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
|
|
|
(2).should.be.at.most(2);
|
|
|
|
(2).should.not.be.at.most(1);
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
(6).should.be.at.most(5, 'blah');
|
|
|
|
}, "blah: expected 6 to be at most 5");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
(6).should.not.be.at.most(10, 'blah');
|
|
|
|
}, "blah: expected 6 to be above 10");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({foo: 1}).should.have.length.of.at.most(3, 'blah');
|
|
|
|
}, "blah: expected { foo: 1 } to have a property 'length'");
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('match(regexp)', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
'foobar'.should.match(/^foo/)
|
|
|
|
'foobar'.should.not.match(/^bar/)
|
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
'foobar'.should.match(/^bar/i, 'blah')
|
|
|
|
}, "blah: expected 'foobar' to match /^bar/i");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
'foobar'.should.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
|
|
|
'test'.should.have.length(4);
|
|
|
|
'test'.should.not.have.length(3);
|
|
|
|
[1,2,3].should.have.length(3);
|
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
(4).should.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 06:09:40 +00:00
|
|
|
'asd'.should.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(){
|
2013-06-05 21:53:34 +00:00
|
|
|
var a = new Date(1, 2, 3)
|
|
|
|
, b = new Date(4, 5, 6);
|
|
|
|
|
|
|
|
a.should.eql(a);
|
|
|
|
a.should.not.eql(b);
|
|
|
|
a.should.not.eql({});
|
2012-01-02 05:45:06 +00:00
|
|
|
'test'.should.eql('test');
|
|
|
|
({ foo: 'bar' }).should.eql({ foo: 'bar' });
|
2013-06-04 22:11:28 +00:00
|
|
|
/a/.should.eql(/a/);
|
|
|
|
/a/.should.not.eql(/b/);
|
2013-06-05 21:53:34 +00:00
|
|
|
/a/.should.not.eql({});
|
2013-06-05 20:26:42 +00:00
|
|
|
/a/g.should.eql(/a/g);
|
|
|
|
/a/g.should.not.eql(/b/g);
|
|
|
|
/a/i.should.eql(/a/i);
|
|
|
|
/a/i.should.not.eql(/b/i);
|
|
|
|
/a/m.should.eql(/a/m);
|
|
|
|
/a/m.should.not.eql(/b/m);
|
2012-01-02 05:45:06 +00:00
|
|
|
(1).should.eql(1);
|
|
|
|
'4'.should.not.eql(4);
|
|
|
|
|
2016-04-08 00:15:29 +00:00
|
|
|
if (typeof Symbol === 'function') {
|
|
|
|
var sym = Symbol();
|
|
|
|
sym.should.eql(sym);
|
|
|
|
}
|
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
(4).should.eql(3, 'blah');
|
|
|
|
}, 'blah: expected 4 to deeply equal 3');
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('equal(val)', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
'test'.should.equal('test');
|
|
|
|
(1).should.equal(1);
|
|
|
|
|
2016-04-08 00:15:29 +00:00
|
|
|
if (typeof Symbol === 'function') {
|
|
|
|
var sym = Symbol();
|
|
|
|
sym.should.equal(sym);
|
|
|
|
}
|
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
(4).should.equal(3, 'blah');
|
|
|
|
}, 'blah: expected 4 to equal 3');
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
'4'.should.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('empty', function(){
|
2012-02-29 19:51:42 +00:00
|
|
|
function FakeArgs() {};
|
|
|
|
FakeArgs.prototype.length = 0;
|
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
''.should.be.empty;
|
2012-03-07 16:09:52 +00:00
|
|
|
'foo'.should.not.be.empty;
|
|
|
|
([]).should.be.empty;
|
|
|
|
(['foo']).should.not.be.empty;
|
2012-02-29 19:51:42 +00:00
|
|
|
(new FakeArgs).should.be.empty;
|
2012-03-07 16:09:52 +00:00
|
|
|
({arguments: 0}).should.not.be.empty;
|
2012-02-29 19:51:42 +00:00
|
|
|
({}).should.be.empty;
|
2012-03-07 16:09:52 +00:00
|
|
|
({foo: 'bar'}).should.not.be.empty;
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-03-07 16:09:52 +00:00
|
|
|
''.should.not.be.empty;
|
|
|
|
}, "expected \'\' not to be empty");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-03-07 16:09:52 +00:00
|
|
|
'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;
|
2012-12-30 11:25:17 +00:00
|
|
|
}, "expected { length: 0 } not to be empty");
|
2012-03-07 16:09:52 +00:00
|
|
|
|
|
|
|
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");
|
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
|
|
|
'test'.should.have.property('length');
|
|
|
|
(4).should.not.have.property('length');
|
2016-02-17 05:07:32 +00:00
|
|
|
({ 1: 1 }).should.have.property(1);
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
|
|
|
'asd'.should.have.property('foo');
|
|
|
|
}, "expected 'asd' to have a property 'foo'");
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('property(name, val)', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
'test'.should.have.property('length', 4);
|
|
|
|
'asd'.should.have.property('constructor', String);
|
2016-02-17 05:07:32 +00:00
|
|
|
({ 1: 1 }).should.have.property(1, 1);
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
'asd'.should.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 06:09:40 +00:00
|
|
|
'asd'.should.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 06:09:40 +00:00
|
|
|
'asd'.should.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 06:09:40 +00:00
|
|
|
'asd'.should.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('ownProperty(name)', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
'test'.should.have.ownProperty('length');
|
|
|
|
'test'.should.haveOwnProperty('length');
|
|
|
|
({ length: 12 }).should.have.ownProperty('length');
|
2016-02-17 05:07:32 +00:00
|
|
|
({ 1: 1 }).should.have.ownProperty(1);
|
2012-01-02 05:45:06 +00:00
|
|
|
|
2016-04-24 22:57:55 +00:00
|
|
|
var objNoHasOwnProperty = {hasOwnProperty: null};
|
|
|
|
objNoHasOwnProperty.a = 'a';
|
|
|
|
objNoHasOwnProperty.should.have.ownProperty('a');
|
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
({ length: 12 }).should.not.have.ownProperty('length', 'blah');
|
|
|
|
}, "blah: expected { length: 12 } to not have own property 'length'");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2015-03-26 21:08:53 +00:00
|
|
|
it('ownPropertyDescriptor(name)', function(){
|
|
|
|
'test'.should.haveOwnPropertyDescriptor('length');
|
|
|
|
'test'.should.have.ownPropertyDescriptor('length');
|
|
|
|
'test'.should.not.have.ownPropertyDescriptor('foo');
|
|
|
|
|
2016-02-17 05:07:32 +00:00
|
|
|
({ 1: 1 }).should.have.ownPropertyDescriptor(1);
|
|
|
|
|
|
|
|
var obj = { },
|
|
|
|
obj2 = { };
|
2015-03-26 21:08:53 +00:00
|
|
|
var descriptor = {
|
|
|
|
configurable: false,
|
|
|
|
enumerable: true,
|
|
|
|
writable: true,
|
|
|
|
value: NaN
|
|
|
|
};
|
|
|
|
Object.defineProperty(obj, 'test', descriptor);
|
|
|
|
obj.should.haveOwnPropertyDescriptor('test', descriptor);
|
2016-02-17 05:07:32 +00:00
|
|
|
|
|
|
|
Object.defineProperty(obj2, 1, descriptor);
|
|
|
|
obj2.should.haveOwnPropertyDescriptor(1, descriptor);
|
|
|
|
|
2015-03-26 21:08:53 +00:00
|
|
|
err(function(){
|
|
|
|
obj.should.not.haveOwnPropertyDescriptor('test', descriptor, 'blah');
|
2015-04-07 06:51:57 +00:00
|
|
|
}, /^blah: expected the own property descriptor for 'test' on \{ test: NaN \} to not match \{ [^\}]+ \}$/);
|
2015-03-26 21:08:53 +00:00
|
|
|
err(function(){
|
|
|
|
var wrongDescriptor = {
|
|
|
|
configurable: false,
|
|
|
|
enumerable: true,
|
|
|
|
writable: false,
|
|
|
|
value: NaN
|
|
|
|
};
|
|
|
|
obj.should.haveOwnPropertyDescriptor('test', wrongDescriptor, 'blah');
|
2015-04-07 06:51:57 +00:00
|
|
|
}, /^blah: expected the own property descriptor for 'test' on \{ test: NaN \} to match \{ [^\}]+ \}, got \{ [^\}]+ \}$/);
|
2015-03-26 21:08:53 +00:00
|
|
|
|
|
|
|
err(function(){
|
|
|
|
obj.should.haveOwnPropertyDescriptor('test2', 'blah');
|
|
|
|
}, "blah: expected { test: NaN } to have an own property descriptor for 'test2'");
|
|
|
|
|
|
|
|
obj.should.have.ownPropertyDescriptor('test').and.have.property('enumerable', true);
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('string()', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
'foobar'.should.contain.string('bar');
|
|
|
|
'foobar'.should.contain.string('foo');
|
|
|
|
'foobar'.should.not.contain.string('baz');
|
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
(3).should.contain.string('baz', 'blah');
|
|
|
|
}, "blah: expected 3 to be a string");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
'foobar'.should.contain.string('baz', 'blah');
|
|
|
|
}, "blah: expected 'foobar' to contain 'baz'");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
'foobar'.should.not.contain.string('bar', 'blah');
|
|
|
|
}, "blah: expected 'foobar' to not contain 'bar'");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2015-10-13 03:10:40 +00:00
|
|
|
it('oneOf()', function(){
|
|
|
|
'foo'.should.be.oneOf(['foo', 'bar']);
|
|
|
|
'bar'.should.be.oneOf(['foo', 'bar']);
|
|
|
|
'baz'.should.not.be.oneOf(['foo', 'bar']);
|
|
|
|
'baz'.should.not.be.oneOf([]);
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('include()', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
['foo', 'bar'].should.include('foo');
|
2012-04-20 17:44:23 +00:00
|
|
|
['foo', 'bar'].should.contain('foo');
|
2012-01-02 05:45:06 +00:00
|
|
|
['foo', 'bar'].should.include('bar');
|
|
|
|
[1,2].should.include(1);
|
|
|
|
['foo', 'bar'].should.not.include('baz');
|
|
|
|
['foo', 'bar'].should.not.include(1);
|
2014-01-05 01:10:14 +00:00
|
|
|
({a:1,b:2}).should.include({b:2});
|
|
|
|
({a:1,b:2}).should.not.include({b:3});
|
2012-01-02 05:45:06 +00:00
|
|
|
|
2016-04-08 00:15:29 +00:00
|
|
|
if (typeof Symbol === 'function') {
|
|
|
|
var sym1 = Symbol()
|
|
|
|
, sym2 = Symbol()
|
|
|
|
, sym3 = Symbol();
|
|
|
|
[sym1, sym2].should.include(sym1);
|
|
|
|
[sym1, sym2].should.not.include(sym3);
|
|
|
|
}
|
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
['foo'].should.include('bar', 'blah');
|
|
|
|
}, "blah: expected [ 'foo' ] to include 'bar'");
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
['bar', 'foo'].should.not.include('foo', 'blah');
|
|
|
|
}, "blah: expected [ 'bar', 'foo' ] to not include 'foo'");
|
2014-01-05 01:10:14 +00:00
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({a:1}).should.include({b:2});
|
2015-07-27 22:54:17 +00:00
|
|
|
}, "expected { a: 1 } to have a property 'b'");
|
|
|
|
|
2015-09-12 12:59:51 +00:00
|
|
|
err(function(){
|
|
|
|
(true).should.include(true);
|
|
|
|
}, "object tested must be an array, an object, or a string, but boolean given");
|
|
|
|
|
2015-07-27 22:54:17 +00:00
|
|
|
err(function(){
|
|
|
|
(42).should.include(4);
|
2015-09-12 12:59:51 +00:00
|
|
|
}, "object tested must be an array, an object, or a string, but number given");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
(true).should.not.include(true);
|
|
|
|
}, "object tested must be an array, an object, or a string, but boolean given");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
(42).should.not.include(4);
|
|
|
|
}, "object tested must be an array, an object, or a string, but number given");
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2015-02-07 21:57:03 +00:00
|
|
|
it('keys(array|Object|arguments)', function(){
|
2012-01-02 05:45:06 +00:00
|
|
|
({ foo: 1 }).should.have.keys(['foo']);
|
2015-02-07 21:57:03 +00:00
|
|
|
({ foo: 1 }).should.have.keys({ 'foo': 6 });
|
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
({ foo: 1, bar: 2 }).should.have.keys(['foo', 'bar']);
|
|
|
|
({ foo: 1, bar: 2 }).should.have.keys('foo', 'bar');
|
2015-02-07 21:57:03 +00:00
|
|
|
({ foo: 1, bar: 2 }).should.have.keys({ 'foo': 6, 'bar': 7 });
|
|
|
|
|
2012-04-20 17:44:23 +00:00
|
|
|
({ foo: 1, bar: 2, baz: 3 }).should.include.keys('foo', 'bar');
|
2012-01-02 05:45:06 +00:00
|
|
|
({ foo: 1, bar: 2, baz: 3 }).should.contain.keys('bar', 'foo');
|
|
|
|
({ foo: 1, bar: 2, baz: 3 }).should.contain.keys('baz');
|
|
|
|
|
|
|
|
({ foo: 1, bar: 2 }).should.contain.keys('foo');
|
|
|
|
({ foo: 1, bar: 2 }).should.contain.keys('bar', 'foo');
|
|
|
|
({ foo: 1, bar: 2 }).should.contain.keys(['foo']);
|
|
|
|
({ foo: 1, bar: 2 }).should.contain.keys(['bar']);
|
|
|
|
({ foo: 1, bar: 2 }).should.contain.keys(['bar', 'foo']);
|
2015-02-07 21:57:03 +00:00
|
|
|
({ foo: 1, bar: 2 }).should.contain.keys({ 'foo': 6 });
|
|
|
|
({ foo: 1, bar: 2 }).should.contain.keys({ 'bar': 7 });
|
|
|
|
({ foo: 1, bar: 2 }).should.contain.keys({ 'foo': 6 });
|
2012-01-02 05:45:06 +00:00
|
|
|
|
|
|
|
({ foo: 1, bar: 2 }).should.not.have.keys('baz');
|
|
|
|
({ foo: 1, bar: 2 }).should.not.have.keys('foo', 'baz');
|
|
|
|
({ foo: 1, bar: 2 }).should.not.contain.keys('baz');
|
|
|
|
({ foo: 1, bar: 2 }).should.not.contain.keys('foo', 'baz');
|
|
|
|
({ foo: 1, bar: 2 }).should.not.contain.keys('baz', 'foo');
|
|
|
|
|
2014-12-01 04:00:11 +00:00
|
|
|
({ foo: 1, bar: 2 }).should.have.any.keys('foo', 'baz');
|
|
|
|
({ foo: 1, bar: 2 }).should.have.any.keys('foo');
|
|
|
|
({ foo: 1, bar: 2 }).should.contain.any.keys('bar', 'baz');
|
|
|
|
({ foo: 1, bar: 2 }).should.contain.any.keys(['foo']);
|
|
|
|
({ foo: 1, bar: 2 }).should.have.all.keys(['bar', 'foo']);
|
|
|
|
({ foo: 1, bar: 2 }).should.contain.all.keys(['bar', 'foo']);
|
2015-02-07 21:57:03 +00:00
|
|
|
({ foo: 1, bar: 2 }).should.contain.any.keys({ 'foo': 6 });
|
|
|
|
({ foo: 1, bar: 2 }).should.have.all.keys({ 'foo': 6, 'bar': 7 });
|
|
|
|
({ foo: 1, bar: 2 }).should.contain.all.keys({ 'bar': 7, 'foo': 6 });
|
2014-12-01 04:00:11 +00:00
|
|
|
|
|
|
|
({ foo: 1, bar: 2 }).should.not.have.any.keys('baz', 'abc', 'def');
|
|
|
|
({ foo: 1, bar: 2 }).should.not.have.any.keys('baz');
|
|
|
|
({ foo: 1, bar: 2 }).should.not.contain.any.keys('baz');
|
|
|
|
({ foo: 1, bar: 2 }).should.not.have.all.keys(['baz', 'foo']);
|
|
|
|
({ foo: 1, bar: 2 }).should.not.contain.all.keys(['baz', 'foo']);
|
2015-02-07 21:57:03 +00:00
|
|
|
({ foo: 1, bar: 2 }).should.not.have.all.keys({ 'baz': 8, 'foo': 7 });
|
2016-03-05 21:54:33 +00:00
|
|
|
|
2015-02-07 21:57:03 +00:00
|
|
|
({ foo: 1, bar: 2 }).should.not.contain.all.keys({ 'baz': 8, 'foo': 7 });
|
2014-12-01 04:00:11 +00:00
|
|
|
|
2016-02-17 05:07:32 +00:00
|
|
|
({ 1: 1, 2: 2 }).should.have.keys(1, 2);
|
|
|
|
({ 1: 1, 2: 2 }).should.have.any.keys(1, 3);
|
|
|
|
({ 1: 1, 2: 2 }).should.contain.keys(1);
|
|
|
|
|
2016-04-08 23:52:30 +00:00
|
|
|
var enumProp1 = 'enumProp1'
|
|
|
|
, enumProp2 = 'enumProp2'
|
|
|
|
, nonEnumProp = 'nonEnumProp'
|
|
|
|
, obj = {};
|
|
|
|
|
|
|
|
obj[enumProp1] = 'enumProp1';
|
|
|
|
obj[enumProp2] = 'enumProp2';
|
|
|
|
|
|
|
|
Object.defineProperty(obj, nonEnumProp, {
|
|
|
|
enumerable: false,
|
|
|
|
value: 'nonEnumProp'
|
|
|
|
});
|
|
|
|
|
|
|
|
obj.should.have.all.keys([enumProp1, enumProp2]);
|
|
|
|
obj.should.not.have.all.keys([enumProp1, enumProp2, nonEnumProp]);
|
|
|
|
|
|
|
|
if (typeof Symbol === 'function') {
|
|
|
|
var sym1 = Symbol('sym1')
|
|
|
|
, sym2 = Symbol('sym2')
|
|
|
|
, sym3 = Symbol('sym3')
|
|
|
|
, str = 'str'
|
|
|
|
, obj = {};
|
|
|
|
|
|
|
|
obj[sym1] = 'sym1';
|
|
|
|
obj[sym2] = 'sym2';
|
|
|
|
obj[str] = 'str';
|
|
|
|
|
|
|
|
Object.defineProperty(obj, sym3, {
|
|
|
|
enumerable: false,
|
|
|
|
value: 'sym3'
|
|
|
|
});
|
|
|
|
|
|
|
|
obj.should.have.all.keys([sym1, sym2, str]);
|
|
|
|
obj.should.not.have.all.keys([sym1, sym2, sym3, str]);
|
|
|
|
}
|
|
|
|
|
2016-03-05 21:54:33 +00:00
|
|
|
if (typeof Map !== 'undefined') {
|
2016-05-15 13:52:39 +00:00
|
|
|
// Not using Map constructor args because not supported in IE 11.
|
|
|
|
var aKey = {thisIs: 'anExampleObject'}
|
|
|
|
, anotherKey = {doingThisBecauseOf: 'referential equality'}
|
|
|
|
, testMap = new Map();
|
|
|
|
|
|
|
|
testMap.set(aKey, 'aValue');
|
|
|
|
testMap.set(anotherKey, 'anotherValue');
|
|
|
|
|
|
|
|
testMap.should.have.any.keys(aKey);
|
|
|
|
testMap.should.have.any.keys('thisDoesNotExist', 'thisToo', aKey);
|
|
|
|
testMap.should.have.all.keys(aKey, anotherKey);
|
|
|
|
|
|
|
|
testMap.should.contain.all.keys(aKey);
|
|
|
|
testMap.should.not.contain.all.keys(aKey, 'thisDoesNotExist');
|
|
|
|
testMap.should.not.have.any.keys({iDoNot: 'exist'});
|
|
|
|
testMap.should.not.have.all.keys('thisDoesNotExist', 'thisToo', anotherKey);
|
|
|
|
|
|
|
|
testMap.should.have.any.keys([aKey]);
|
|
|
|
testMap.should.have.any.keys([20, 1, aKey]);
|
|
|
|
testMap.should.have.all.keys([aKey, anotherKey]);
|
|
|
|
|
|
|
|
testMap.should.not.have.any.keys([{13: 37}, 'thisDoesNotExist', 'thisToo']);
|
|
|
|
testMap.should.not.have.any.keys([20, 1, {13: 37}]);
|
|
|
|
testMap.should.not.have.all.keys([aKey, {'iDoNot': 'exist'}]);
|
2016-03-05 21:54:33 +00:00
|
|
|
|
2016-04-08 23:52:30 +00:00
|
|
|
var weirdMapKey1 = Object.create(null)
|
|
|
|
, weirdMapKey2 = {toString: NaN}
|
2016-05-15 13:52:39 +00:00
|
|
|
, weirdMapKey3 = []
|
|
|
|
, weirdMap = new Map();
|
|
|
|
|
|
|
|
weirdMap.set(weirdMapKey1, 'val1');
|
|
|
|
weirdMap.set(weirdMapKey2, 'val2');
|
|
|
|
|
|
|
|
weirdMap.should.have.all.keys([weirdMapKey1, weirdMapKey2]);
|
|
|
|
weirdMap.should.not.have.all.keys([weirdMapKey1, weirdMapKey3]);
|
2016-04-08 23:52:30 +00:00
|
|
|
|
|
|
|
if (typeof Symbol === 'function') {
|
|
|
|
var symMapKey1 = Symbol()
|
|
|
|
, symMapKey2 = Symbol()
|
2016-05-15 13:52:39 +00:00
|
|
|
, symMapKey3 = Symbol()
|
|
|
|
, symMap = new Map();
|
|
|
|
|
|
|
|
symMap.set(symMapKey1, 'val1');
|
|
|
|
symMap.set(symMapKey2, 'val2');
|
|
|
|
|
|
|
|
symMap.should.have.all.keys(symMapKey1, symMapKey2);
|
|
|
|
symMap.should.have.any.keys(symMapKey1, symMapKey3);
|
|
|
|
symMap.should.contain.all.keys(symMapKey2, symMapKey1);
|
|
|
|
symMap.should.contain.any.keys(symMapKey3, symMapKey1);
|
|
|
|
|
|
|
|
symMap.should.not.have.all.keys(symMapKey1, symMapKey3);
|
|
|
|
symMap.should.not.have.any.keys(symMapKey3);
|
|
|
|
symMap.should.not.contain.all.keys(symMapKey3, symMapKey1);
|
|
|
|
symMap.should.not.contain.any.keys(symMapKey3);
|
|
|
|
}
|
2016-04-08 23:52:30 +00:00
|
|
|
|
2016-05-15 13:52:39 +00:00
|
|
|
var errMap = new Map();
|
2016-04-08 23:52:30 +00:00
|
|
|
|
2016-05-15 13:52:39 +00:00
|
|
|
errMap.set({ foo: 1 });
|
2016-04-08 23:52:30 +00:00
|
|
|
|
2016-03-05 21:54:33 +00:00
|
|
|
err(function(){
|
2016-05-15 13:52:39 +00:00
|
|
|
errMap.should.have.keys();
|
2016-03-05 21:54:33 +00:00
|
|
|
}, "keys required");
|
|
|
|
|
|
|
|
err(function(){
|
2016-05-15 13:52:39 +00:00
|
|
|
errMap.should.have.keys([]);
|
2016-03-05 21:54:33 +00:00
|
|
|
}, "keys required");
|
|
|
|
|
|
|
|
err(function(){
|
2016-05-15 13:52:39 +00:00
|
|
|
errMap.should.contain.keys();
|
2016-03-05 21:54:33 +00:00
|
|
|
}, "keys required");
|
|
|
|
|
|
|
|
err(function(){
|
2016-05-15 13:52:39 +00:00
|
|
|
errMap.should.contain.keys([]);
|
2016-03-05 21:54:33 +00:00
|
|
|
}, "keys required");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof Set !== 'undefined') {
|
2016-05-15 13:52:39 +00:00
|
|
|
// Not using Set constructor args because not supported in IE 11.
|
|
|
|
var aKey = {thisIs: 'anExampleObject'}
|
|
|
|
, anotherKey = {doingThisBecauseOf: 'referential equality'}
|
|
|
|
, testSet = new Set();
|
|
|
|
|
|
|
|
testSet.add(aKey);
|
|
|
|
testSet.add(anotherKey);
|
2016-03-05 21:54:33 +00:00
|
|
|
|
2016-05-15 13:52:39 +00:00
|
|
|
testSet.should.have.any.keys(aKey);
|
|
|
|
testSet.should.have.any.keys('thisDoesNotExist', 'thisToo', aKey);
|
|
|
|
testSet.should.have.all.keys(aKey, anotherKey);
|
2016-03-05 21:54:33 +00:00
|
|
|
|
2016-05-15 13:52:39 +00:00
|
|
|
testSet.should.contain.all.keys(aKey);
|
|
|
|
testSet.should.not.contain.all.keys(aKey, 'thisDoesNotExist');
|
2016-03-05 21:54:33 +00:00
|
|
|
|
2016-05-15 13:52:39 +00:00
|
|
|
testSet.should.not.have.any.keys({iDoNot: 'exist'});
|
|
|
|
testSet.should.not.have.any.keys('thisIsNotAkey', {iDoNot: 'exist'}, {33: 20});
|
|
|
|
testSet.should.not.have.all.keys('thisDoesNotExist', 'thisToo', anotherKey);
|
2016-03-05 21:54:33 +00:00
|
|
|
|
2016-05-15 13:52:39 +00:00
|
|
|
testSet.should.have.any.keys([aKey]);
|
|
|
|
testSet.should.have.any.keys([20, 1, aKey]);
|
|
|
|
testSet.should.have.all.keys([aKey, anotherKey]);
|
2016-03-05 21:54:33 +00:00
|
|
|
|
2016-05-15 13:52:39 +00:00
|
|
|
testSet.should.not.have.any.keys([{13: 37}, 'thisDoesNotExist', 'thisToo']);
|
|
|
|
testSet.should.not.have.any.keys([20, 1, {13: 37}]);
|
|
|
|
testSet.should.not.have.all.keys([aKey, {'iDoNot': 'exist'}]);
|
2016-03-05 21:54:33 +00:00
|
|
|
|
2016-04-08 23:52:30 +00:00
|
|
|
var weirdSetKey1 = Object.create(null)
|
|
|
|
, weirdSetKey2 = {toString: NaN}
|
2016-05-15 13:52:39 +00:00
|
|
|
, weirdSetKey3 = []
|
|
|
|
, weirdSet = new Set();
|
|
|
|
|
|
|
|
weirdSet.add(weirdSetKey1);
|
|
|
|
weirdSet.add(weirdSetKey2);
|
|
|
|
|
|
|
|
weirdSet.should.have.all.keys([weirdSetKey1, weirdSetKey2]);
|
|
|
|
weirdSet.should.not.have.all.keys([weirdSetKey1, weirdSetKey3]);
|
2016-04-08 23:52:30 +00:00
|
|
|
|
|
|
|
if (typeof Symbol === 'function') {
|
|
|
|
var symSetKey1 = Symbol()
|
|
|
|
, symSetKey2 = Symbol()
|
2016-05-15 13:52:39 +00:00
|
|
|
, symSetKey3 = Symbol()
|
|
|
|
, symSet = new Set();
|
|
|
|
|
|
|
|
symSet.add(symSetKey1);
|
|
|
|
symSet.add(symSetKey2);
|
|
|
|
|
|
|
|
symSet.should.have.all.keys(symSetKey1, symSetKey2);
|
|
|
|
symSet.should.have.any.keys(symSetKey1, symSetKey3);
|
|
|
|
symSet.should.contain.all.keys(symSetKey2, symSetKey1);
|
|
|
|
symSet.should.contain.any.keys(symSetKey3, symSetKey1);
|
|
|
|
|
|
|
|
symSet.should.not.have.all.keys(symSetKey1, symSetKey3);
|
|
|
|
symSet.should.not.have.any.keys(symSetKey3);
|
|
|
|
symSet.should.not.contain.all.keys(symSetKey3, symSetKey1);
|
|
|
|
symSet.should.not.contain.any.keys(symSetKey3);
|
|
|
|
}
|
2016-04-08 23:52:30 +00:00
|
|
|
|
2016-05-15 13:52:39 +00:00
|
|
|
var errSet = new Set();
|
2016-04-08 23:52:30 +00:00
|
|
|
|
2016-05-15 13:52:39 +00:00
|
|
|
errSet.add({ foo: 1 });
|
2016-04-08 23:52:30 +00:00
|
|
|
|
2016-03-05 21:54:33 +00:00
|
|
|
err(function(){
|
2016-05-15 13:52:39 +00:00
|
|
|
errSet.should.have.keys();
|
2016-03-05 21:54:33 +00:00
|
|
|
}, "keys required");
|
|
|
|
|
|
|
|
err(function(){
|
2016-05-15 13:52:39 +00:00
|
|
|
errSet.should.have.keys([]);
|
2016-03-05 21:54:33 +00:00
|
|
|
}, "keys required");
|
|
|
|
|
|
|
|
err(function(){
|
2016-05-15 13:52:39 +00:00
|
|
|
errSet.should.contain.keys();
|
2016-03-05 21:54:33 +00:00
|
|
|
}, "keys required");
|
|
|
|
|
|
|
|
err(function(){
|
2016-05-15 13:52:39 +00:00
|
|
|
errSet.should.contain.keys([]);
|
2016-03-05 21:54:33 +00:00
|
|
|
}, "keys required");
|
|
|
|
}
|
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.have.keys();
|
|
|
|
}, "keys required");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.have.keys([]);
|
|
|
|
}, "keys required");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.not.have.keys([]);
|
|
|
|
}, "keys required");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.contain.keys([]);
|
|
|
|
}, "keys required");
|
|
|
|
|
2016-03-05 21:54:33 +00:00
|
|
|
var mixedArgsMsg = 'when testing keys against an object or an array you must give a single Array|Object|String argument or multiple String arguments'
|
2015-02-07 21:57:03 +00:00
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({}).should.contain.keys(['a'], "b");
|
|
|
|
}, mixedArgsMsg);
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({}).should.contain.keys({ 'a': 1 }, "b");
|
|
|
|
}, mixedArgsMsg);
|
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.have.keys(['bar']);
|
|
|
|
}, "expected { foo: 1 } to have key 'bar'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.have.keys(['bar', 'baz']);
|
|
|
|
}, "expected { foo: 1 } to have keys 'bar', and 'baz'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.have.keys(['foo', 'bar', 'baz']);
|
|
|
|
}, "expected { foo: 1 } to have keys 'foo', 'bar', and 'baz'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.not.have.keys(['foo']);
|
|
|
|
}, "expected { foo: 1 } to not have key 'foo'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.not.have.keys(['foo']);
|
|
|
|
}, "expected { foo: 1 } to not have key 'foo'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1, bar: 2 }).should.not.have.keys(['foo', 'bar']);
|
|
|
|
}, "expected { foo: 1, bar: 2 } to not have keys 'foo', and 'bar'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.not.contain.keys(['foo']);
|
|
|
|
}, "expected { foo: 1 } to not contain key 'foo'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.contain.keys('foo', 'bar');
|
|
|
|
}, "expected { foo: 1 } to contain keys 'foo', and 'bar'");
|
2014-12-01 04:00:11 +00:00
|
|
|
|
|
|
|
err(function() {
|
|
|
|
({ foo: 1 }).should.have.any.keys('baz');
|
|
|
|
}, "expected { foo: 1 } to have key 'baz'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1, bar: 2 }).should.not.have.all.keys(['foo', 'bar']);
|
|
|
|
}, "expected { foo: 1, bar: 2 } to not have keys 'foo', and 'bar'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1, bar: 2 }).should.not.have.any.keys(['foo', 'baz']);
|
|
|
|
}, "expected { foo: 1, bar: 2 } to not have keys 'foo', or 'baz'");
|
2015-02-07 21:57:03 +00:00
|
|
|
|
|
|
|
// repeat previous tests with Object as arg.
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.have.keys({ 'bar': 1 });
|
|
|
|
}, "expected { foo: 1 } to have key 'bar'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.have.keys({ 'bar': 1, 'baz': 1});
|
|
|
|
}, "expected { foo: 1 } to have keys 'bar', and 'baz'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.have.keys({ 'foo': 1, 'bar': 1, 'baz': 1});
|
|
|
|
}, "expected { foo: 1 } to have keys 'foo', 'bar', and 'baz'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.not.have.keys({ 'foo': 1 });
|
|
|
|
}, "expected { foo: 1 } to not have key 'foo'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.not.have.keys({ 'foo': 1 });
|
|
|
|
}, "expected { foo: 1 } to not have key 'foo'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1, bar: 2 }).should.not.have.keys({ 'foo': 1, 'bar': 1});
|
|
|
|
}, "expected { foo: 1, bar: 2 } to not have keys 'foo', and 'bar'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.not.contain.keys({ 'foo': 1 });
|
|
|
|
}, "expected { foo: 1 } to not contain key 'foo'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1 }).should.contain.keys('foo', 'bar');
|
|
|
|
}, "expected { foo: 1 } to contain keys 'foo', and 'bar'");
|
|
|
|
|
|
|
|
err(function() {
|
|
|
|
({ foo: 1 }).should.have.any.keys('baz');
|
|
|
|
}, "expected { foo: 1 } to have key 'baz'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1, bar: 2 }).should.not.have.all.keys({ 'foo': 1, 'bar': 1});
|
|
|
|
}, "expected { foo: 1, bar: 2 } to not have keys 'foo', and 'bar'");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
({ foo: 1, bar: 2 }).should.not.have.any.keys({ 'foo': 1, 'baz': 1});
|
|
|
|
}, "expected { foo: 1, bar: 2 } to not have keys 'foo', or 'baz'");
|
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
});
|
|
|
|
|
2015-02-04 22:48:16 +00:00
|
|
|
it('keys(array) will not mutate array (#359)', function () {
|
|
|
|
var expected = [ 'b', 'a' ];
|
|
|
|
var original_order = [ 'b', 'a' ];
|
|
|
|
var obj = { "b": 1, "a": 1 };
|
|
|
|
expected.should.deep.equal(original_order);
|
|
|
|
obj.should.keys(original_order);
|
|
|
|
expected.should.deep.equal(original_order);
|
|
|
|
});
|
|
|
|
|
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'); }
|
2013-01-27 19:11:50 +00:00
|
|
|
, stringErrFn = function () { throw '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
|
|
|
|
|
|
|
(goodFn).should.not.throw();
|
|
|
|
(goodFn).should.not.throw(Error);
|
2012-04-06 22:19:28 +00:00
|
|
|
(goodFn).should.not.throw(specificError);
|
2012-01-02 05:45:06 +00:00
|
|
|
(badFn).should.throw();
|
|
|
|
(badFn).should.throw(Error);
|
|
|
|
(badFn).should.not.throw(ReferenceError);
|
2012-04-06 22:19:28 +00:00
|
|
|
(badFn).should.not.throw(specificError);
|
2013-01-27 19:11:50 +00:00
|
|
|
(stringErrFn).should.throw();
|
|
|
|
(stringErrFn).should.not.throw(ReferenceError);
|
|
|
|
(stringErrFn).should.not.throw(specificError);
|
2012-01-02 05:45:06 +00:00
|
|
|
(refErrFn).should.throw();
|
|
|
|
(refErrFn).should.throw(ReferenceError);
|
2012-04-06 21:39:08 +00:00
|
|
|
(refErrFn).should.throw(Error);
|
2012-01-02 05:45:06 +00:00
|
|
|
(refErrFn).should.not.throw(TypeError);
|
2012-04-06 22:19:28 +00:00
|
|
|
(refErrFn).should.not.throw(specificError);
|
2012-04-06 21:57:54 +00:00
|
|
|
(ickyErrFn).should.throw();
|
|
|
|
(ickyErrFn).should.throw(PoorlyConstructedError);
|
|
|
|
(ickyErrFn).should.throw(Error);
|
2012-04-06 22:19:28 +00:00
|
|
|
(ickyErrFn).should.not.throw(specificError);
|
|
|
|
(specificErrFn).should.throw(specificError);
|
2012-01-02 05:45:06 +00:00
|
|
|
|
2012-02-07 21:39:08 +00:00
|
|
|
(badFn).should.throw(/testing/);
|
2012-03-07 16:38:58 +00:00
|
|
|
(badFn).should.throw('testing');
|
2012-02-07 21:39:08 +00:00
|
|
|
(badFn).should.not.throw(/hello/);
|
2013-01-27 19:11:50 +00:00
|
|
|
(badFn).should.not.throw('hello');
|
2012-03-07 16:38:58 +00:00
|
|
|
(badFn).should.throw(Error, /testing/);
|
|
|
|
(badFn).should.throw(Error, 'testing');
|
2012-02-07 21:39:08 +00:00
|
|
|
|
2013-01-27 19:11:50 +00:00
|
|
|
(stringErrFn).should.throw(/testing/);
|
|
|
|
(stringErrFn).should.throw('testing');
|
|
|
|
(stringErrFn).should.not.throw(/hello/);
|
|
|
|
(stringErrFn).should.not.throw('hello');
|
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
should.throw(badFn);
|
|
|
|
should.throw(refErrFn, ReferenceError);
|
2012-04-06 21:39:08 +00:00
|
|
|
should.throw(refErrFn, Error);
|
2012-04-06 21:57:54 +00:00
|
|
|
should.throw(ickyErrFn, PoorlyConstructedError);
|
2012-04-06 22:19:28 +00:00
|
|
|
should.throw(specificErrFn, specificError);
|
2012-01-02 05:45:06 +00:00
|
|
|
should.not.throw(goodFn);
|
|
|
|
should.not.throw(badFn, ReferenceError);
|
2012-04-06 22:19:28 +00:00
|
|
|
should.not.throw(badFn, specificError);
|
2012-01-02 05:45:06 +00:00
|
|
|
|
2012-03-07 16:38:58 +00:00
|
|
|
should.throw(badFn, Error, /testing/);
|
|
|
|
should.throw(badFn, Error, 'testing');
|
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
err(function(){
|
|
|
|
(goodFn).should.throw();
|
|
|
|
}, "expected [Function] to throw an error");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
(goodFn).should.throw(ReferenceError);
|
|
|
|
}, "expected [Function] to throw ReferenceError");
|
|
|
|
|
2012-04-06 22:19:28 +00:00
|
|
|
err(function(){
|
|
|
|
(goodFn).should.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(){
|
|
|
|
(badFn).should.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(){
|
|
|
|
(badFn).should.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(){
|
|
|
|
(badFn).should.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(){
|
|
|
|
(badFn).should.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
|
|
|
|
2013-01-27 19:11:50 +00:00
|
|
|
err(function(){
|
|
|
|
(stringErrFn).should.not.throw();
|
|
|
|
}, "expected [Function] to not throw an error but 'testing' was thrown");
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
(stringErrFn).should.throw(ReferenceError);
|
2013-02-03 23:03:40 +00:00
|
|
|
}, "expected [Function] to throw 'ReferenceError' but 'testing' was thrown");
|
2013-01-27 19:11:50 +00:00
|
|
|
|
|
|
|
err(function(){
|
|
|
|
(stringErrFn).should.throw(specificError);
|
2013-10-23 21:06:39 +00:00
|
|
|
}, "expected [Function] to throw 'RangeError: boo' but 'testing' was thrown");
|
2013-01-27 19:11:50 +00:00
|
|
|
|
|
|
|
err(function(){
|
|
|
|
(stringErrFn).should.not.throw('testing');
|
|
|
|
}, "expected [Function] to throw error not including 'testing'");
|
|
|
|
|
2012-01-02 05:45:06 +00:00
|
|
|
err(function(){
|
|
|
|
(refErrFn).should.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(){
|
|
|
|
(badFn).should.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(){
|
|
|
|
(ickyErrFn).should.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(){
|
|
|
|
(ickyErrFn).should.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(){
|
|
|
|
(specificErrFn).should.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(){
|
|
|
|
(specificErrFn).should.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 (){
|
|
|
|
(badFn).should.not.throw(/testing/);
|
|
|
|
}, "expected [Function] to throw error not matching /testing/");
|
|
|
|
|
|
|
|
err(function () {
|
|
|
|
(badFn).should.throw(/hello/);
|
|
|
|
}, "expected [Function] to throw error matching /hello/ but got \'testing\'");
|
2012-03-07 16:38:58 +00:00
|
|
|
|
|
|
|
err(function () {
|
2012-09-05 06:09:40 +00:00
|
|
|
(badFn).should.throw(Error, /hello/, 'blah');
|
|
|
|
}, "blah: expected [Function] to throw error matching /hello/ but got 'testing'");
|
2012-03-07 16:38:58 +00:00
|
|
|
|
|
|
|
err(function () {
|
2012-09-05 06:09:40 +00:00
|
|
|
(badFn).should.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
|
|
|
});
|
2012-02-24 19:53:33 +00:00
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('respondTo', function(){
|
2012-02-24 19:53:33 +00:00
|
|
|
function Foo(){};
|
|
|
|
Foo.prototype.bar = function(){};
|
2012-06-02 16:41:54 +00:00
|
|
|
Foo.func = function(){};
|
2012-02-24 19:53:33 +00:00
|
|
|
|
|
|
|
var bar = {};
|
|
|
|
bar.foo = function(){};
|
|
|
|
|
|
|
|
Foo.should.respondTo('bar');
|
|
|
|
Foo.should.not.respondTo('foo');
|
2012-06-02 16:41:54 +00:00
|
|
|
Foo.should.itself.respondTo('func');
|
|
|
|
Foo.should.itself.not.respondTo('bar');
|
2012-02-24 19:53:33 +00:00
|
|
|
|
|
|
|
bar.should.respondTo('foo');
|
|
|
|
|
|
|
|
err(function(){
|
2013-02-03 23:03:40 +00:00
|
|
|
Foo.should.respondTo('baz', 'constructor');
|
|
|
|
}, /^(constructor: expected)(.*)(\[Function: Foo\])(.*)(to respond to \'baz\')$/);
|
2012-02-24 19:53:33 +00:00
|
|
|
|
|
|
|
err(function(){
|
2013-02-03 23:03:40 +00:00
|
|
|
bar.should.respondTo('baz', 'object');
|
|
|
|
}, /^(object: expected)(.*)(\{ foo: \[Function\] \}|\{ Object \()(.*)(to respond to \'baz\')$/);
|
2012-02-24 19:53:33 +00:00
|
|
|
});
|
2012-02-24 20:30:30 +00:00
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('satisfy', function(){
|
2013-02-03 23:03:40 +00:00
|
|
|
var matcher = function (num){
|
2012-02-24 20:30:30 +00:00
|
|
|
return num === 1;
|
|
|
|
};
|
|
|
|
|
2012-02-24 20:46:04 +00:00
|
|
|
(1).should.satisfy(matcher);
|
2012-02-24 20:30:30 +00:00
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
(2).should.satisfy(matcher, 'blah');
|
|
|
|
}, "blah: expected 2 to satisfy [Function]");
|
2012-02-24 20:30:30 +00:00
|
|
|
});
|
2012-02-24 22:00:15 +00:00
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('closeTo', function(){
|
2012-02-24 22:00:15 +00:00
|
|
|
(1.5).should.be.closeTo(1.0, 0.5);
|
|
|
|
|
|
|
|
err(function(){
|
2012-09-05 06:09:40 +00:00
|
|
|
(2).should.be.closeTo(1.0, 0.5, 'blah');
|
|
|
|
}, "blah: expected 2 to be close to 1 +/- 0.5");
|
2014-07-13 00:57:13 +00:00
|
|
|
|
|
|
|
err(function() {
|
|
|
|
[1.5].should.be.closeTo(1.0, 0.5);
|
|
|
|
}, "expected [ 1.5 ] to be a number");
|
|
|
|
|
|
|
|
err(function() {
|
|
|
|
(1.5).should.be.closeTo("1.0", 0.5);
|
2015-10-04 05:30:14 +00:00
|
|
|
}, "the arguments to closeTo or approximately must be numbers");
|
2014-07-13 00:57:13 +00:00
|
|
|
|
|
|
|
err(function() {
|
|
|
|
(1.5).should.be.closeTo(1.0, true);
|
2015-10-04 05:30:14 +00:00
|
|
|
}, "the arguments to closeTo or approximately must be numbers");
|
|
|
|
});
|
2015-10-13 03:10:40 +00:00
|
|
|
|
2015-10-04 05:30:14 +00:00
|
|
|
it('approximately', function(){
|
|
|
|
(1.5).should.be.approximately(1.0, 0.5);
|
|
|
|
|
|
|
|
err(function(){
|
|
|
|
(2).should.be.approximately(1.0, 0.5, 'blah');
|
|
|
|
}, "blah: expected 2 to be close to 1 +/- 0.5");
|
|
|
|
|
|
|
|
err(function() {
|
|
|
|
[1.5].should.be.approximately(1.0, 0.5);
|
|
|
|
}, "expected [ 1.5 ] to be a number");
|
|
|
|
|
|
|
|
err(function() {
|
|
|
|
(1.5).should.be.approximately("1.0", 0.5);
|
|
|
|
}, "the arguments to closeTo or approximately must be numbers");
|
|
|
|
|
|
|
|
err(function() {
|
|
|
|
(1.5).should.be.approximately(1.0, true);
|
|
|
|
}, "the arguments to closeTo or approximately must be numbers");
|
2012-02-24 22:00:15 +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
|
|
|
[1, 2, 3].should.include.members([3]);
|
|
|
|
[1, 2, 3].should.include.members([]);
|
|
|
|
[1, 2, 3].should.include.members([2, 1]);
|
2013-04-14 19:40:32 +00:00
|
|
|
|
2013-04-14 23:07:12 +00:00
|
|
|
[1, 2, 3].should.not.include.members([999]);
|
|
|
|
[].should.not.include.members([23]);
|
2013-04-14 19:40:32 +00:00
|
|
|
|
|
|
|
err(function() {
|
2013-04-14 23:07:12 +00:00
|
|
|
[].should.include.members([43]);
|
2013-04-14 19:40:32 +00:00
|
|
|
}, 'expected [] to be a superset of [ 43 ]');
|
|
|
|
|
|
|
|
err(function() {
|
2013-04-14 23:07:12 +00:00
|
|
|
[5, 2, 1].should.not.include.members([2]);
|
2013-04-14 19:40:32 +00:00
|
|
|
}, 'expected [ 5, 2, 1 ] to not be a superset of [ 2 ]');
|
|
|
|
|
|
|
|
err(function() {
|
2013-04-14 23:07:12 +00:00
|
|
|
'foo'.should.include.members([12]);
|
2013-04-14 19:40:32 +00:00
|
|
|
}, "expected 'foo' to be an array");
|
|
|
|
|
|
|
|
err(function() {
|
2013-04-14 23:07:12 +00:00
|
|
|
[1, 2, 3].should.include.members('o');
|
2013-04-14 19:40:32 +00:00
|
|
|
}, "expected 'o' to be an array");
|
|
|
|
});
|
|
|
|
|
2013-09-17 21:22:36 +00:00
|
|
|
it('memberEquals', function() {
|
2013-04-14 23:07:12 +00:00
|
|
|
[1, 2, 3].should.have.same.members([3, 2, 1]);
|
|
|
|
[5, 4].should.have.same.members([5, 4]);
|
|
|
|
[].should.have.same.members([]);
|
2013-04-14 19:40:32 +00:00
|
|
|
|
|
|
|
err(function() {
|
2013-04-14 23:07:12 +00:00
|
|
|
[1, 2, 3].should.have.same.members([]);
|
2013-04-14 19:40:32 +00:00
|
|
|
}, 'expected [ 1, 2, 3 ] to have the same members as []');
|
|
|
|
|
|
|
|
err(function() {
|
2013-04-14 23:07:12 +00:00
|
|
|
[1, 2, 3].should.have.same.members(4);
|
2013-04-14 19:40:32 +00:00
|
|
|
}, 'expected 4 to be an array');
|
|
|
|
});
|
2014-12-28 01:10:59 +00:00
|
|
|
|
|
|
|
it('change', function() {
|
2014-12-29 17:45:25 +00:00
|
|
|
var obj = { value: 10, str: 'foo' },
|
2016-02-01 22:08:51 +00:00
|
|
|
heroes = ['spiderman', 'superman'],
|
2014-12-28 01:10:59 +00:00
|
|
|
fn = function() { obj.value += 5 },
|
2014-12-29 17:45:25 +00:00
|
|
|
sameFn = function() { obj.value += 0 },
|
2016-02-22 20:15:34 +00:00
|
|
|
decFn = function() { obj.value -= 20 },
|
2016-01-31 17:44:17 +00:00
|
|
|
bangFn = function() { obj.str += '!' },
|
2016-02-01 22:08:51 +00:00
|
|
|
batFn = function() { heroes.push('batman') },
|
|
|
|
lenFn = function() { return heroes.length },
|
2016-01-31 17:44:17 +00:00
|
|
|
noFn = function() { return null };
|
2014-12-28 01:10:59 +00:00
|
|
|
|
|
|
|
fn.should.change(obj, 'value');
|
2016-02-22 20:15:34 +00:00
|
|
|
fn.should.change(obj, 'value').by(5);
|
|
|
|
fn.should.change(obj, 'value').by(-5);
|
|
|
|
fn.should.change(obj, 'value').but.not.by(10);
|
|
|
|
|
|
|
|
decFn.should.change(obj, 'value');
|
|
|
|
decFn.should.change(obj, 'value').by(20);
|
|
|
|
decFn.should.change(obj, 'value').but.not.by(19);
|
|
|
|
|
2014-12-28 01:10:59 +00:00
|
|
|
sameFn.should.not.change(obj, 'value');
|
2016-02-22 20:15:34 +00:00
|
|
|
|
2014-12-29 17:45:25 +00:00
|
|
|
sameFn.should.not.change(obj, 'str');
|
|
|
|
bangFn.should.change(obj, 'str');
|
2016-02-22 20:15:34 +00:00
|
|
|
|
2016-02-01 22:08:51 +00:00
|
|
|
batFn.should.change(lenFn);
|
2016-02-22 20:15:34 +00:00
|
|
|
batFn.should.change(lenFn).by(1);
|
|
|
|
batFn.should.change(lenFn).but.not.by(2);
|
2016-01-31 17:44:17 +00:00
|
|
|
noFn.should.not.change(lenFn);
|
2014-12-28 01:10:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('increase, decrease', function() {
|
|
|
|
var obj = { value: 10 },
|
2016-02-01 22:01:54 +00:00
|
|
|
arr = ['one', 'two'],
|
|
|
|
pFn = function() { arr.push('three') },
|
|
|
|
popFn = function() { arr.pop() },
|
|
|
|
lenFn = function() { return arr.length },
|
|
|
|
nFn = function() { return null },
|
2014-12-28 01:10:59 +00:00
|
|
|
incFn = function() { obj.value += 2 },
|
|
|
|
decFn = function() { obj.value -= 3 },
|
|
|
|
smFn = function() { obj.value += 0 };
|
|
|
|
|
|
|
|
smFn.should.not.increase(obj, 'value');
|
|
|
|
decFn.should.not.increase(obj, 'value');
|
|
|
|
incFn.should.increase(obj, 'value');
|
2016-02-22 20:15:34 +00:00
|
|
|
incFn.should.increase(obj, 'value').by(2);
|
|
|
|
incFn.should.increase(obj, 'value').but.not.by(1);
|
2014-12-28 01:10:59 +00:00
|
|
|
|
|
|
|
smFn.should.not.decrease(obj, 'value');
|
|
|
|
incFn.should.not.decrease(obj, 'value');
|
|
|
|
decFn.should.decrease(obj, 'value');
|
2016-02-22 20:15:34 +00:00
|
|
|
decFn.should.decrease(obj, 'value').by(3);
|
|
|
|
decFn.should.decrease(obj, 'value').but.not.by(2);
|
2016-02-01 22:01:54 +00:00
|
|
|
|
|
|
|
nFn.should.not.increase(lenFn);
|
2016-02-22 20:15:34 +00:00
|
|
|
nFn.should.not.decrease(lenFn);
|
|
|
|
|
|
|
|
popFn.should.decrease(lenFn);
|
2016-02-01 22:01:54 +00:00
|
|
|
popFn.should.not.increase(lenFn);
|
|
|
|
|
2016-02-22 20:15:34 +00:00
|
|
|
pFn.should.increase(lenFn);
|
2016-02-01 22:01:54 +00:00
|
|
|
pFn.should.not.decrease(lenFn);
|
2016-02-22 20:15:34 +00:00
|
|
|
|
|
|
|
pFn.should.increase(lenFn).by(1);
|
|
|
|
pFn.should.increase(lenFn).but.not.by(2);
|
|
|
|
|
|
|
|
popFn.should.decrease(lenFn).by(1);
|
|
|
|
popFn.should.decrease(lenFn).but.not.by(2);
|
2014-12-28 01:10:59 +00:00
|
|
|
});
|
2015-07-12 12:56:15 +00:00
|
|
|
|
|
|
|
it('extensible', function() {
|
|
|
|
var nonExtensibleObject = Object.preventExtensions({});
|
|
|
|
|
|
|
|
({}).should.be.extensible;
|
|
|
|
nonExtensibleObject.should.not.be.extensible;
|
|
|
|
|
|
|
|
err(function() {
|
|
|
|
nonExtensibleObject.should.be.extensible;
|
|
|
|
}, 'expected {} to be extensible');
|
|
|
|
|
|
|
|
err(function() {
|
|
|
|
({}).should.not.be.extensible;
|
|
|
|
}, 'expected {} to not be extensible');
|
2015-07-26 19:42:46 +00:00
|
|
|
|
|
|
|
// Making sure ES6-like Object.isExtensible response is respected for all primitive types
|
|
|
|
|
|
|
|
(42).should.not.be.extensible;
|
|
|
|
'foo'.should.not.be.extensible;
|
|
|
|
false.should.not.be.extensible;
|
|
|
|
|
2016-04-08 00:15:29 +00:00
|
|
|
if (typeof Symbol === 'function') {
|
|
|
|
Symbol().should.not.be.extensible;
|
|
|
|
}
|
|
|
|
|
2015-07-26 19:42:46 +00:00
|
|
|
err(function() {
|
|
|
|
(42).should.be.extensible;
|
|
|
|
}, 'expected 42 to be extensible');
|
|
|
|
|
|
|
|
err(function() {
|
|
|
|
'foo'.should.be.extensible;
|
|
|
|
}, 'expected \'foo\' to be extensible');
|
|
|
|
|
|
|
|
err(function() {
|
|
|
|
false.should.be.extensible;
|
|
|
|
}, 'expected false to be extensible');
|
2015-07-12 12:56:15 +00:00
|
|
|
});
|
|
|
|
|
2015-07-12 12:57:26 +00:00
|
|
|
it('sealed', function() {
|
|
|
|
var sealedObject = Object.seal({});
|
|
|
|
|
|
|
|
sealedObject.should.be.sealed;
|
|
|
|
({}).should.not.be.sealed;
|
|
|
|
|
|
|
|
err(function() {
|
|
|
|
({}).should.be.sealed;
|
|
|
|
}, 'expected {} to be sealed');
|
|
|
|
|
|
|
|
err(function() {
|
|
|
|
sealedObject.should.not.be.sealed;
|
|
|
|
}, 'expected {} to not be sealed');
|
2015-07-26 19:31:48 +00:00
|
|
|
|
|
|
|
// Making sure ES6-like Object.isSealed response is respected for all primitive types
|
|
|
|
|
|
|
|
(42).should.be.sealed;
|
|
|
|
'foo'.should.be.sealed;
|
|
|
|
false.should.be.sealed;
|
|
|
|
|
2016-04-08 00:15:29 +00:00
|
|
|
if (typeof Symbol === 'function') {
|
|
|
|
Symbol().should.be.sealed;
|
|
|
|
}
|
|
|
|
|
2015-07-26 19:31:48 +00:00
|
|
|
err(function() {
|
|
|
|
(42).should.not.be.sealed;
|
|
|
|
}, 'expected 42 to not be sealed');
|
|
|
|
|
|
|
|
err(function() {
|
|
|
|
'foo'.should.not.be.sealed;
|
|
|
|
}, 'expected \'foo\' to not be sealed');
|
|
|
|
|
|
|
|
err(function() {
|
|
|
|
false.should.not.be.sealed;
|
|
|
|
}, 'expected false to not be sealed');
|
2015-07-12 12:57:26 +00:00
|
|
|
});
|
|
|
|
|
2015-07-12 12:57:42 +00:00
|
|
|
it('frozen', function() {
|
|
|
|
var frozenObject = Object.freeze({});
|
|
|
|
|
|
|
|
frozenObject.should.be.frozen;
|
|
|
|
({}).should.not.be.frozen;
|
|
|
|
|
|
|
|
err(function() {
|
|
|
|
({}).should.be.frozen;
|
|
|
|
}, 'expected {} to be frozen');
|
|
|
|
|
|
|
|
err(function() {
|
|
|
|
frozenObject.should.not.be.frozen;
|
|
|
|
}, 'expected {} to not be frozen');
|
2015-07-21 21:58:25 +00:00
|
|
|
|
|
|
|
// Making sure ES6-like Object.isFrozen response is respected for all primitive types
|
|
|
|
|
|
|
|
(42).should.be.frozen;
|
|
|
|
'foo'.should.be.frozen;
|
|
|
|
false.should.be.frozen;
|
|
|
|
|
2016-04-08 00:15:29 +00:00
|
|
|
if (typeof Symbol === 'function') {
|
|
|
|
Symbol().should.be.frozen;
|
|
|
|
}
|
|
|
|
|
2015-07-21 21:58:25 +00:00
|
|
|
err(function() {
|
|
|
|
(42).should.not.be.frozen;
|
|
|
|
}, 'expected 42 to not be frozen');
|
|
|
|
|
|
|
|
err(function() {
|
|
|
|
'foo'.should.not.be.frozen;
|
|
|
|
}, 'expected \'foo\' to not be frozen');
|
|
|
|
|
|
|
|
err(function() {
|
|
|
|
false.should.not.be.frozen;
|
|
|
|
}, 'expected false to not be frozen');
|
2015-07-12 12:57:42 +00:00
|
|
|
});
|
2012-02-07 21:39:08 +00:00
|
|
|
});
|