Comparing version 0.1.4 to 0.1.5
12
chai.js
@@ -947,3 +947,3 @@ !function (name, definition) { | ||
exports.version = '0.1.3'; | ||
exports.version = '0.1.5'; | ||
@@ -1576,2 +1576,6 @@ exports.expect = require('./interface/expect'); | ||
should.exist = function (val) { | ||
new Assertion(val).to.exist; | ||
} | ||
// negation | ||
@@ -1581,3 +1585,3 @@ should.not = {} | ||
should.not.equal = function (val1, val2) { | ||
new Assertion(val).to.not.equal(val2); | ||
new Assertion(val1).to.not.equal(val2); | ||
}; | ||
@@ -1589,2 +1593,6 @@ | ||
should.not.exist = function (val) { | ||
new Assertion(val).to.not.exist; | ||
} | ||
return should; | ||
@@ -1591,0 +1599,0 @@ }; |
0.1.5 / 2012-01-02 | ||
================== | ||
* browser tests pass | ||
* type in should.not.equal | ||
* test for should (not) exist | ||
* added should.exist and should.not.exist | ||
* browser uses tdd | ||
* convert tests to tdd | ||
0.1.4 / 2011-12-26 | ||
@@ -3,0 +13,0 @@ ================== |
@@ -9,3 +9,3 @@ /*! | ||
exports.version = '0.1.4'; | ||
exports.version = '0.1.5'; | ||
@@ -12,0 +12,0 @@ exports.expect = require('./interface/expect'); |
@@ -40,2 +40,6 @@ /*! | ||
should.exist = function (val) { | ||
new Assertion(val).to.exist; | ||
} | ||
// negation | ||
@@ -45,3 +49,3 @@ should.not = {} | ||
should.not.equal = function (val1, val2) { | ||
new Assertion(val).to.not.equal(val2); | ||
new Assertion(val1).to.not.equal(val2); | ||
}; | ||
@@ -53,3 +57,7 @@ | ||
should.not.exist = function (val) { | ||
new Assertion(val).to.not.exist; | ||
} | ||
return should; | ||
}; |
@@ -6,3 +6,3 @@ { | ||
"keywords": [ "test", "assertion", "assert", "testing" ], | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
@@ -22,415 +22,399 @@ /*! | ||
var expectTests = module.exports = { | ||
'expect': { | ||
'test .version': function(){ | ||
expect(chai.version).to.match(/^\d+\.\d+\.\d+$/); | ||
}, | ||
suite('expect', function () { | ||
'test double require': function(){ | ||
//require('chai').expect().to.equal(expect); | ||
}, | ||
test('=.version', function() { | ||
expect(chai.version).to.match(/^\d+\.\d+\.\d+$/); | ||
}); | ||
'test assertion': function(){ | ||
expect('test').to.be.a('string'); | ||
expect('foo').to.equal('foo'); | ||
}, | ||
test('=double require', function(){ | ||
//require('chai').expect().to.equal(expect); | ||
}); | ||
'test true': function(){ | ||
expect(true).to.be.true; | ||
expect(false).to.not.be.true; | ||
expect(1).to.not.be.true; | ||
test('assertion', function(){ | ||
expect('test').to.be.a('string'); | ||
expect('foo').to.equal('foo'); | ||
}); | ||
err(function(){ | ||
expect('test').to.be.true; | ||
}, "expected 'test' to be true") | ||
}, | ||
test('true', function(){ | ||
expect(true).to.be.true; | ||
expect(false).to.not.be.true; | ||
expect(1).to.not.be.true; | ||
'test ok': function(){ | ||
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('test').to.be.true; | ||
}, "expected 'test' to be true") | ||
}); | ||
err(function(){ | ||
expect('').to.be.ok; | ||
}, "expected '' to be truthy"); | ||
test('ok', function(){ | ||
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('test').to.not.be.ok; | ||
}, "expected 'test' to be falsey"); | ||
}, | ||
err(function(){ | ||
expect('').to.be.ok; | ||
}, "expected '' to be truthy"); | ||
'test false': function(){ | ||
expect(false).to.be.false; | ||
expect(true).to.not.be.false; | ||
expect(0).to.not.be.false; | ||
err(function(){ | ||
expect('test').to.not.be.ok; | ||
}, "expected 'test' to be falsey"); | ||
}); | ||
err(function(){ | ||
expect('').to.be.false; | ||
}, "expected '' to be false") | ||
}, | ||
test('false', function(){ | ||
expect(false).to.be.false; | ||
expect(true).to.not.be.false; | ||
expect(0).to.not.be.false; | ||
'text exist': function(){ | ||
var foo = 'bar' | ||
, bar; | ||
expect(foo).to.exist; | ||
expect(bar).to.not.exist; | ||
}, | ||
err(function(){ | ||
expect('').to.be.false; | ||
}, "expected '' to be false") | ||
}); | ||
'test arguments': function(){ | ||
var args = (function(){ return arguments; })(1,2,3); | ||
expect(args).to.be.arguments; | ||
expect([]).to.not.be.arguments; | ||
}, | ||
test('exist', function(){ | ||
var foo = 'bar' | ||
, bar; | ||
expect(foo).to.exist; | ||
expect(bar).to.not.exist; | ||
}); | ||
'test .equal()': function(){ | ||
var foo; | ||
expect(undefined).to.equal(foo); | ||
}, | ||
test('arguments', function(){ | ||
var args = (function(){ return arguments; })(1,2,3); | ||
expect(args).to.be.arguments; | ||
expect([]).to.not.be.arguments; | ||
}); | ||
'test typeof': function(){ | ||
expect('test').to.be.a('string'); | ||
test('.equal()', function(){ | ||
var foo; | ||
expect(undefined).to.equal(foo); | ||
}); | ||
err(function(){ | ||
expect('test').to.not.be.a('string'); | ||
}, "expected 'test' not to be a string"); | ||
test('typeof', function(){ | ||
expect('test').to.be.a('string'); | ||
expect(5).to.be.a('number'); | ||
err(function(){ | ||
expect('test').to.not.be.a('string'); | ||
}, "expected 'test' not to be a string"); | ||
err(function(){ | ||
expect(5).to.not.be.a('number'); | ||
}, "expected 5 not to be a number"); | ||
}, | ||
expect(5).to.be.a('number'); | ||
'test instanceof': function(){ | ||
function Foo(){} | ||
expect(new Foo()).to.be.an.instanceof(Foo); | ||
err(function(){ | ||
expect(5).to.not.be.a('number'); | ||
}, "expected 5 not to be a number"); | ||
}); | ||
err(function(){ | ||
expect(3).to.an.instanceof(Foo); | ||
}, "expected 3 to be an instance of Foo"); | ||
}, | ||
test('instanceof', function(){ | ||
function Foo(){} | ||
expect(new Foo()).to.be.an.instanceof(Foo); | ||
'test within(start, finish)': function(){ | ||
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); | ||
err(function(){ | ||
expect(3).to.an.instanceof(Foo); | ||
}, "expected 3 to be an instance of Foo"); | ||
}); | ||
err(function(){ | ||
expect(5).to.not.be.within(4,6); | ||
}, "expected 5 to not be within 4..6"); | ||
test('within(start, finish)', function(){ | ||
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); | ||
err(function(){ | ||
expect(10).to.be.within(50,100); | ||
}, "expected 10 to be within 50..100"); | ||
}, | ||
err(function(){ | ||
expect(5).to.not.be.within(4,6); | ||
}, "expected 5 to not be within 4..6"); | ||
'test above(n)': function(){ | ||
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); | ||
err(function(){ | ||
expect(10).to.be.within(50,100); | ||
}, "expected 10 to be within 50..100"); | ||
}); | ||
err(function(){ | ||
expect(5).to.be.above(6); | ||
}, "expected 5 to be above 6"); | ||
test('above(n)', function(){ | ||
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); | ||
err(function(){ | ||
expect(10).to.not.be.above(6); | ||
}, "expected 10 to be below 6"); | ||
}, | ||
err(function(){ | ||
expect(5).to.be.above(6); | ||
}, "expected 5 to be above 6"); | ||
'test match(regexp)': function(){ | ||
expect('foobar').to.match(/^foo/) | ||
expect('foobar').to.not.match(/^bar/) | ||
err(function(){ | ||
expect(10).to.not.be.above(6); | ||
}, "expected 10 to be below 6"); | ||
}); | ||
err(function(){ | ||
expect('foobar').to.match(/^bar/i) | ||
}, "expected 'foobar' to match /^bar/i"); | ||
test('match(regexp)', function(){ | ||
expect('foobar').to.match(/^foo/) | ||
expect('foobar').to.not.match(/^bar/) | ||
err(function(){ | ||
expect('foobar').to.not.match(/^foo/i) | ||
}, "expected 'foobar' not to match /^foo/i"); | ||
}, | ||
err(function(){ | ||
expect('foobar').to.match(/^bar/i) | ||
}, "expected 'foobar' to match /^bar/i"); | ||
'test length(n)': function(){ | ||
expect('test').to.have.length(4); | ||
expect('test').to.not.have.length(3); | ||
expect([1,2,3]).to.have.length(3); | ||
err(function(){ | ||
expect('foobar').to.not.match(/^foo/i) | ||
}, "expected 'foobar' not to match /^foo/i"); | ||
}); | ||
err(function(){ | ||
expect(4).to.have.length(3); | ||
}, 'expected 4 to have a property \'length\''); | ||
test('length(n)', function(){ | ||
expect('test').to.have.length(4); | ||
expect('test').to.not.have.length(3); | ||
expect([1,2,3]).to.have.length(3); | ||
err(function(){ | ||
expect('asd').to.not.have.length(3); | ||
}, "expected 'asd' to not have a length of 3"); | ||
}, | ||
err(function(){ | ||
expect(4).to.have.length(3); | ||
}, 'expected 4 to have a property \'length\''); | ||
'test eql(val)': function(){ | ||
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(){ | ||
expect('asd').to.not.have.length(3); | ||
}, "expected 'asd' to not have a length of 3"); | ||
}); | ||
err(function(){ | ||
expect(4).to.eql(3); | ||
}, 'expected 4 to equal 3'); | ||
}, | ||
test('eql(val)', function(){ | ||
expect('test').to.eql('test'); | ||
expect({ foo: 'bar' }).to.eql({ foo: 'bar' }); | ||
expect(1).to.eql(1); | ||
expect('4').to.not.eql(4); | ||
'test equal(val)': function(){ | ||
expect('test').to.equal('test'); | ||
expect(1).to.equal(1); | ||
err(function(){ | ||
expect(4).to.eql(3); | ||
}, 'expected 4 to equal 3'); | ||
}); | ||
err(function(){ | ||
expect(4).to.equal(3); | ||
}, 'expected 4 to equal 3'); | ||
test('equal(val)', function(){ | ||
expect('test').to.equal('test'); | ||
expect(1).to.equal(1); | ||
err(function(){ | ||
expect('4').to.equal(4); | ||
}, "expected '4' to equal 4"); | ||
}, | ||
err(function(){ | ||
expect(4).to.equal(3); | ||
}, 'expected 4 to equal 3'); | ||
'test empty': function(){ | ||
expect('').to.be.empty; | ||
expect([]).to.be.empty; | ||
expect({ length: 0 }).to.be.empty; | ||
err(function(){ | ||
expect('4').to.equal(4); | ||
}, "expected '4' to equal 4"); | ||
}); | ||
err(function(){ | ||
expect({}).to.be.empty; | ||
}, 'expected {} to have a property \'length\''); | ||
test('empty', function(){ | ||
expect('').to.be.empty; | ||
expect([]).to.be.empty; | ||
expect({ length: 0 }).to.be.empty; | ||
err(function(){ | ||
expect([ 'hello', 'world' ]).to.be.empty; | ||
}, "expected [ \'hello\', \'world\' ] to be empty"); | ||
err(function(){ | ||
expect({}).to.be.empty; | ||
}, 'expected {} to have a property \'length\''); | ||
err(function(){ | ||
expect([ { hello: 'world' } ]).to.be.empty; | ||
}, "expected [ { hello: \'world\' } ] to be empty"); | ||
err(function(){ | ||
expect([ 'hello', 'world' ]).to.be.empty; | ||
}, "expected [ \'hello\', \'world\' ] to be empty"); | ||
err(function(){ | ||
expect('asd').to.be.empty; | ||
}, "expected 'asd' to be empty"); | ||
err(function(){ | ||
expect([ { hello: 'world' } ]).to.be.empty; | ||
}, "expected [ { hello: \'world\' } ] to be empty"); | ||
err(function(){ | ||
expect('').to.not.be.empty; | ||
}, "expected '' not to be empty"); | ||
}, | ||
err(function(){ | ||
expect('asd').to.be.empty; | ||
}, "expected 'asd' to be empty"); | ||
'test property(name)': function(){ | ||
expect('test').to.have.property('length'); | ||
expect(4).to.not.have.property('length'); | ||
err(function(){ | ||
expect('').to.not.be.empty; | ||
}, "expected '' not to be empty"); | ||
}); | ||
err(function(){ | ||
expect('asd').to.have.property('foo'); | ||
}, "expected 'asd' to have a property 'foo'"); | ||
}, | ||
test('property(name)', function(){ | ||
expect('test').to.have.property('length'); | ||
expect(4).to.not.have.property('length'); | ||
'test property(name, val)': function(){ | ||
expect('test').to.have.property('length', 4); | ||
expect('asd').to.have.property('constructor', String); | ||
err(function(){ | ||
expect('asd').to.have.property('foo'); | ||
}, "expected 'asd' to have a property 'foo'"); | ||
}); | ||
err(function(){ | ||
expect('asd').to.have.property('length', 4); | ||
}, "expected 'asd' to have a property 'length' of 4, but got 3"); | ||
test('property(name, val)', function(){ | ||
expect('test').to.have.property('length', 4); | ||
expect('asd').to.have.property('constructor', String); | ||
err(function(){ | ||
expect('asd').to.not.have.property('length', 3); | ||
}, "expected 'asd' to not have a property 'length' of 3"); | ||
err(function(){ | ||
expect('asd').to.have.property('length', 4); | ||
}, "expected 'asd' to have a property 'length' of 4, but got 3"); | ||
err(function(){ | ||
expect('asd').to.not.have.property('foo', 3); | ||
}, "'asd' has no property 'foo'"); | ||
err(function(){ | ||
expect('asd').to.not.have.property('length', 3); | ||
}, "expected 'asd' to not have a property 'length' of 3"); | ||
err(function(){ | ||
expect('asd').to.have.property('constructor', Number); | ||
}, "expected 'asd' to have a property 'constructor' of [Function: Number], but got [Function: String]"); | ||
}, | ||
err(function(){ | ||
expect('asd').to.not.have.property('foo', 3); | ||
}, "'asd' has no property 'foo'"); | ||
'test ownProperty(name)': function(){ | ||
expect('test').to.have.ownProperty('length'); | ||
expect('test').to.haveOwnProperty('length'); | ||
expect({ length: 12 }).to.have.ownProperty('length'); | ||
err(function(){ | ||
expect('asd').to.have.property('constructor', Number); | ||
}, "expected 'asd' to have a property 'constructor' of [Function: Number], but got [Function: String]"); | ||
}); | ||
err(function(){ | ||
expect({ length: 12 }).to.not.have.ownProperty('length'); | ||
}, "expected { length: 12 } to not have own property 'length'"); | ||
}, | ||
test('ownProperty(name)', function(){ | ||
expect('test').to.have.ownProperty('length'); | ||
expect('test').to.haveOwnProperty('length'); | ||
expect({ length: 12 }).to.have.ownProperty('length'); | ||
'test string()': function(){ | ||
expect('foobar').to.have.string('bar'); | ||
expect('foobar').to.have.string('foo'); | ||
expect('foobar').to.not.have.string('baz'); | ||
err(function(){ | ||
expect({ length: 12 }).to.not.have.ownProperty('length'); | ||
}, "expected { length: 12 } to not have own property 'length'"); | ||
}); | ||
err(function(){ | ||
expect(3).to.have.string('baz'); | ||
}, "expected 3 to be a string"); | ||
test('string()', function(){ | ||
expect('foobar').to.have.string('bar'); | ||
expect('foobar').to.have.string('foo'); | ||
expect('foobar').to.not.have.string('baz'); | ||
err(function(){ | ||
expect('foobar').to.have.string('baz'); | ||
}, "expected 'foobar' to contain 'baz'"); | ||
err(function(){ | ||
expect(3).to.have.string('baz'); | ||
}, "expected 3 to be a string"); | ||
err(function(){ | ||
expect('foobar').to.not.have.string('bar'); | ||
}, "expected 'foobar' to not contain 'bar'"); | ||
}, | ||
err(function(){ | ||
expect('foobar').to.have.string('baz'); | ||
}, "expected 'foobar' to contain 'baz'"); | ||
'test include()': function(){ | ||
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); | ||
err(function(){ | ||
expect('foobar').to.not.have.string('bar'); | ||
}, "expected 'foobar' to not contain 'bar'"); | ||
}); | ||
err(function(){ | ||
expect(['foo']).to.include('bar'); | ||
}, "expected [ 'foo' ] to include 'bar'"); | ||
test('include()', function(){ | ||
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); | ||
err(function(){ | ||
expect(['bar', 'foo']).to.not.include('foo'); | ||
}, "expected [ 'bar', 'foo' ] to not include 'foo'"); | ||
}, | ||
err(function(){ | ||
expect(['foo']).to.include('bar'); | ||
}, "expected [ 'foo' ] to include 'bar'"); | ||
'test keys(array)': function(){ | ||
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'); | ||
err(function(){ | ||
expect(['bar', 'foo']).to.not.include('foo'); | ||
}, "expected [ 'bar', 'foo' ] to not include 'foo'"); | ||
}); | ||
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']); | ||
test('keys(array)', function(){ | ||
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.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'); | ||
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']); | ||
err(function(){ | ||
expect({ foo: 1 }).to.have.keys(); | ||
}, "keys required"); | ||
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.have.keys([]); | ||
}, "keys required"); | ||
err(function(){ | ||
expect({ foo: 1 }).to.contain.keys([]); | ||
}, "keys required"); | ||
err(function(){ | ||
expect({ foo: 1 }).to.not.have.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.contain.keys([]); | ||
}, "keys required"); | ||
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(['bar']); | ||
}, "expected { foo: 1 } to have key 'bar'"); | ||
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.have.keys(['bar', 'baz']); | ||
}, "expected { foo: 1 } to have keys '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.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.have.keys(['foo']); | ||
}, "expected { foo: 1 } to not have key 'foo'"); | ||
err(function(){ | ||
expect({ foo: 1 }).to.not.contain.keys(['foo']); | ||
}, "expected { foo: 1 } to not contain 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.contain.keys('foo', 'bar'); | ||
}, "expected { foo: 1 } to contain keys 'foo', and 'bar'"); | ||
}, | ||
err(function(){ | ||
expect({ foo: 1 }).to.not.contain.keys(['foo']); | ||
}, "expected { foo: 1 } to not contain key 'foo'"); | ||
'test chaining': function(){ | ||
var tea = { name: 'chai', extras: ['milk', 'sugar', 'smile'] }; | ||
expect(tea).to.have.property('extras').with.lengthOf(3); | ||
err(function(){ | ||
expect({ foo: 1 }).to.contain.keys('foo', 'bar'); | ||
}, "expected { foo: 1 } to contain keys 'foo', and 'bar'"); | ||
}); | ||
err(function(){ | ||
expect(tea).to.have.property('extras').with.lengthOf(4); | ||
}, "expected [ 'milk', 'sugar', 'smile' ] to have a length of 4 but got 3"); | ||
test('chaining', function(){ | ||
var tea = { name: 'chai', extras: ['milk', 'sugar', 'smile'] }; | ||
expect(tea).to.have.property('extras').with.lengthOf(3); | ||
expect(tea).to.be.a('object').and.have.property('name', 'chai'); | ||
}, | ||
err(function(){ | ||
expect(tea).to.have.property('extras').with.lengthOf(4); | ||
}, "expected [ 'milk', 'sugar', 'smile' ] to have a length of 4 but got 3"); | ||
'test throw': function () { | ||
var goodFn = function () { 1==1; } | ||
, badFn = function () { throw new Error('testing'); } | ||
, refErrFn = function () { throw new ReferenceError(); }; | ||
expect(tea).to.be.a('object').and.have.property('name', 'chai'); | ||
}); | ||
expect(goodFn).to.not.throw(); | ||
expect(goodFn).to.not.throw(Error); | ||
expect(badFn).to.throw(); | ||
expect(badFn).to.throw(Error); | ||
expect(badFn).to.not.throw(ReferenceError); | ||
expect(refErrFn).to.throw(); | ||
expect(refErrFn).to.throw(ReferenceError); | ||
expect(refErrFn).to.not.throw(Error); | ||
expect(refErrFn).to.not.throw(TypeError); | ||
test('throw', function () { | ||
var goodFn = function () { 1==1; } | ||
, badFn = function () { throw new Error('testing'); } | ||
, refErrFn = function () { throw new ReferenceError(); }; | ||
err(function(){ | ||
expect(goodFn).to.throw(); | ||
}, "expected [Function] to throw an error"); | ||
expect(goodFn).to.not.throw(); | ||
expect(goodFn).to.not.throw(Error); | ||
expect(badFn).to.throw(); | ||
expect(badFn).to.throw(Error); | ||
expect(badFn).to.not.throw(ReferenceError); | ||
expect(refErrFn).to.throw(); | ||
expect(refErrFn).to.throw(ReferenceError); | ||
expect(refErrFn).to.not.throw(Error); | ||
expect(refErrFn).to.not.throw(TypeError); | ||
err(function(){ | ||
expect(goodFn).to.throw(ReferenceError); | ||
}, "expected [Function] to throw ReferenceError"); | ||
err(function(){ | ||
expect(goodFn).to.throw(); | ||
}, "expected [Function] to throw an error"); | ||
err(function(){ | ||
expect(badFn).to.not.throw(); | ||
}, "expected [Function] to not throw an error"); | ||
err(function(){ | ||
expect(goodFn).to.throw(ReferenceError); | ||
}, "expected [Function] to throw ReferenceError"); | ||
err(function(){ | ||
expect(badFn).to.throw(ReferenceError); | ||
}, "expected [Function] to throw ReferenceError but a Error was thrown"); | ||
err(function(){ | ||
expect(badFn).to.not.throw(); | ||
}, "expected [Function] to not throw an error"); | ||
err(function(){ | ||
expect(badFn).to.not.throw(Error); | ||
}, "expected [Function] to not throw Error"); | ||
err(function(){ | ||
expect(badFn).to.throw(ReferenceError); | ||
}, "expected [Function] to throw ReferenceError but a Error was thrown"); | ||
err(function(){ | ||
expect(refErrFn).to.not.throw(ReferenceError); | ||
}, "expected [Function] to not throw ReferenceError"); | ||
err(function(){ | ||
expect(badFn).to.not.throw(Error); | ||
}, "expected [Function] to not throw Error"); | ||
err(function(){ | ||
expect(refErrFn).to.throw(Error); | ||
}, "expected [Function] to throw Error but a ReferenceError was thrown"); | ||
}, | ||
/* | ||
'test async': function (done) { | ||
setTimeout(function() { | ||
err(function(){ | ||
expect(refErrFn).to.not.throw(ReferenceError); | ||
}, "expected [Function] to not throw ReferenceError"); | ||
expect('').to.not.be.empty; | ||
expect([]).to.be.empty; | ||
expect({ length: 0 }).to.be.empty; | ||
err(function(){ | ||
expect(refErrFn).to.throw(Error); | ||
}, "expected [Function] to throw Error but a ReferenceError was thrown"); | ||
}); | ||
err(function(){ | ||
expect({}).to.be.empty; | ||
}, 'expected {} to have a property \'length\''); | ||
done(); | ||
}, 1000); | ||
} | ||
*/ | ||
} | ||
}; | ||
}); |
@@ -21,378 +21,392 @@ /** | ||
var shouldTests = module.exports = { | ||
'should': { | ||
'test .version': function(){ | ||
chai.version.should.match(/^\d+\.\d+\.\d+$/); | ||
}, | ||
suite('should', function() { | ||
'test double require': function(){ | ||
//require('chai').should().should.equal(should); | ||
}, | ||
test('.version', function(){ | ||
chai.version.should.match(/^\d+\.\d+\.\d+$/); | ||
}); | ||
'test assertion': function(){ | ||
'test'.should.be.a('string'); | ||
should.equal('foo', 'foo'); | ||
}, | ||
test('double require', function(){ | ||
//require('chai').should().should.equal(should); | ||
}); | ||
'test true': function(){ | ||
true.should.be.true; | ||
false.should.not.be.true; | ||
(1).should.not.be.true; | ||
test('assertion', function(){ | ||
'test'.should.be.a('string'); | ||
should.equal('foo', 'foo'); | ||
}); | ||
err(function(){ | ||
'test'.should.be.true; | ||
}, "expected 'test' to be true") | ||
}, | ||
test('root exist', function () { | ||
var foo = 'foo' | ||
, bar = undefined; | ||
should.exist(foo); | ||
should.not.exist(bar); | ||
'test ok': function(){ | ||
true.should.be.ok; | ||
false.should.not.be.ok; | ||
(1).should.be.ok; | ||
(0).should.not.be.ok; | ||
err(function () { | ||
should.exist(bar); | ||
}, "expected undefined to exist"); | ||
err(function(){ | ||
''.should.be.ok; | ||
}, "expected '' to be truthy"); | ||
err(function () { | ||
should.not.exist(foo); | ||
}, "expected 'foo' to not exist") | ||
}); | ||
err(function(){ | ||
'test'.should.not.be.ok; | ||
}, "expected 'test' to be falsey"); | ||
}, | ||
test('true', function(){ | ||
true.should.be.true; | ||
false.should.not.be.true; | ||
(1).should.not.be.true; | ||
'test false': function(){ | ||
false.should.be.false; | ||
true.should.not.be.false; | ||
(0).should.not.be.false; | ||
err(function(){ | ||
'test'.should.be.true; | ||
}, "expected 'test' to be true") | ||
}); | ||
err(function(){ | ||
''.should.be.false; | ||
}, "expected '' to be false") | ||
}, | ||
test('ok', function(){ | ||
true.should.be.ok; | ||
false.should.not.be.ok; | ||
(1).should.be.ok; | ||
(0).should.not.be.ok; | ||
'test arguments': function(){ | ||
var args = (function(){ return arguments; })(1,2,3); | ||
args.should.be.arguments; | ||
[].should.not.be.arguments; | ||
}, | ||
err(function(){ | ||
''.should.be.ok; | ||
}, "expected '' to be truthy"); | ||
'test .equal()': function(){ | ||
var foo; | ||
should.equal(undefined, foo); | ||
}, | ||
err(function(){ | ||
'test'.should.not.be.ok; | ||
}, "expected 'test' to be falsey"); | ||
}); | ||
'test typeof': function(){ | ||
'test'.should.be.a('string'); | ||
test('false', function(){ | ||
false.should.be.false; | ||
true.should.not.be.false; | ||
(0).should.not.be.false; | ||
err(function(){ | ||
'test'.should.not.be.a('string'); | ||
}, "expected 'test' not to be a string"); | ||
err(function(){ | ||
''.should.be.false; | ||
}, "expected '' to be false") | ||
}); | ||
(5).should.be.a('number'); | ||
test('arguments', function(){ | ||
var args = (function(){ return arguments; })(1,2,3); | ||
args.should.be.arguments; | ||
[].should.not.be.arguments; | ||
}); | ||
err(function(){ | ||
(5).should.not.be.a('number'); | ||
}, "expected 5 not to be a number"); | ||
}, | ||
test('.equal()', function(){ | ||
var foo; | ||
should.equal(undefined, foo); | ||
}); | ||
'test instanceof': function(){ | ||
function Foo(){} | ||
new Foo().should.be.an.instanceof(Foo); | ||
test('typeof', function(){ | ||
'test'.should.be.a('string'); | ||
err(function(){ | ||
(3).should.an.instanceof(Foo); | ||
}, "expected 3 to be an instance of Foo"); | ||
}, | ||
err(function(){ | ||
'test'.should.not.be.a('string'); | ||
}, "expected 'test' not to be a string"); | ||
'test within(start, finish)': function(){ | ||
(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); | ||
(5).should.be.a('number'); | ||
err(function(){ | ||
(5).should.not.be.within(4,6); | ||
}, "expected 5 to not be within 4..6"); | ||
err(function(){ | ||
(5).should.not.be.a('number'); | ||
}, "expected 5 not to be a number"); | ||
}); | ||
err(function(){ | ||
(10).should.be.within(50,100); | ||
}, "expected 10 to be within 50..100"); | ||
}, | ||
test('instanceof', function(){ | ||
function Foo(){} | ||
new Foo().should.be.an.instanceof(Foo); | ||
'test above(n)': function(){ | ||
(5).should.be.above(2); | ||
(5).should.be.greaterThan(2); | ||
(5).should.not.be.above(5); | ||
(5).should.not.be.above(6); | ||
err(function(){ | ||
(3).should.an.instanceof(Foo); | ||
}, "expected 3 to be an instance of Foo"); | ||
}); | ||
err(function(){ | ||
(5).should.be.above(6); | ||
}, "expected 5 to be above 6"); | ||
test('within(start, finish)', function(){ | ||
(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(){ | ||
(10).should.not.be.above(6); | ||
}, "expected 10 to be below 6"); | ||
}, | ||
err(function(){ | ||
(5).should.not.be.within(4,6); | ||
}, "expected 5 to not be within 4..6"); | ||
'test match(regexp)': function(){ | ||
'foobar'.should.match(/^foo/) | ||
'foobar'.should.not.match(/^bar/) | ||
err(function(){ | ||
(10).should.be.within(50,100); | ||
}, "expected 10 to be within 50..100"); | ||
}); | ||
err(function(){ | ||
'foobar'.should.match(/^bar/i) | ||
}, "expected 'foobar' to match /^bar/i"); | ||
test('above(n)', function(){ | ||
(5).should.be.above(2); | ||
(5).should.be.greaterThan(2); | ||
(5).should.not.be.above(5); | ||
(5).should.not.be.above(6); | ||
err(function(){ | ||
'foobar'.should.not.match(/^foo/i) | ||
}, "expected 'foobar' not to match /^foo/i"); | ||
}, | ||
err(function(){ | ||
(5).should.be.above(6); | ||
}, "expected 5 to be above 6"); | ||
'test length(n)': function(){ | ||
'test'.should.have.length(4); | ||
'test'.should.not.have.length(3); | ||
[1,2,3].should.have.length(3); | ||
err(function(){ | ||
(10).should.not.be.above(6); | ||
}, "expected 10 to be below 6"); | ||
}); | ||
err(function(){ | ||
(4).should.have.length(3); | ||
}, 'expected 4 to have a property \'length\''); | ||
test('match(regexp)', function(){ | ||
'foobar'.should.match(/^foo/) | ||
'foobar'.should.not.match(/^bar/) | ||
err(function(){ | ||
'asd'.should.not.have.length(3); | ||
}, "expected 'asd' to not have a length of 3"); | ||
}, | ||
err(function(){ | ||
'foobar'.should.match(/^bar/i) | ||
}, "expected 'foobar' to match /^bar/i"); | ||
'test eql(val)': function(){ | ||
'test'.should.eql('test'); | ||
({ foo: 'bar' }).should.eql({ foo: 'bar' }); | ||
(1).should.eql(1); | ||
'4'.should.not.eql(4); | ||
err(function(){ | ||
'foobar'.should.not.match(/^foo/i) | ||
}, "expected 'foobar' not to match /^foo/i"); | ||
}); | ||
err(function(){ | ||
(4).should.eql(3); | ||
}, 'expected 4 to equal 3'); | ||
}, | ||
test('length(n)', function(){ | ||
'test'.should.have.length(4); | ||
'test'.should.not.have.length(3); | ||
[1,2,3].should.have.length(3); | ||
'test equal(val)': function(){ | ||
'test'.should.equal('test'); | ||
(1).should.equal(1); | ||
err(function(){ | ||
(4).should.have.length(3); | ||
}, 'expected 4 to have a property \'length\''); | ||
err(function(){ | ||
(4).should.equal(3); | ||
}, 'expected 4 to equal 3'); | ||
err(function(){ | ||
'asd'.should.not.have.length(3); | ||
}, "expected 'asd' to not have a length of 3"); | ||
}); | ||
err(function(){ | ||
'4'.should.equal(4); | ||
}, "expected '4' to equal 4"); | ||
}, | ||
test('eql(val)', function(){ | ||
'test'.should.eql('test'); | ||
({ foo: 'bar' }).should.eql({ foo: 'bar' }); | ||
(1).should.eql(1); | ||
'4'.should.not.eql(4); | ||
'test empty': function(){ | ||
''.should.be.empty; | ||
[].should.be.empty; | ||
({ length: 0 }).should.be.empty; | ||
err(function(){ | ||
(4).should.eql(3); | ||
}, 'expected 4 to equal 3'); | ||
}); | ||
err(function(){ | ||
({}).should.be.empty; | ||
}, 'expected {} to have a property \'length\''); | ||
test('equal(val)', function(){ | ||
'test'.should.equal('test'); | ||
(1).should.equal(1); | ||
err(function(){ | ||
'asd'.should.be.empty; | ||
}, "expected 'asd' to be empty"); | ||
err(function(){ | ||
(4).should.equal(3); | ||
}, 'expected 4 to equal 3'); | ||
err(function(){ | ||
''.should.not.be.empty; | ||
}, "expected '' not to be empty"); | ||
}, | ||
err(function(){ | ||
'4'.should.equal(4); | ||
}, "expected '4' to equal 4"); | ||
}); | ||
'test property(name)': function(){ | ||
'test'.should.have.property('length'); | ||
(4).should.not.have.property('length'); | ||
test('empty', function(){ | ||
''.should.be.empty; | ||
[].should.be.empty; | ||
({ length: 0 }).should.be.empty; | ||
err(function(){ | ||
'asd'.should.have.property('foo'); | ||
}, "expected 'asd' to have a property 'foo'"); | ||
}, | ||
err(function(){ | ||
({}).should.be.empty; | ||
}, 'expected {} to have a property \'length\''); | ||
'test property(name, val)': function(){ | ||
'test'.should.have.property('length', 4); | ||
'asd'.should.have.property('constructor', String); | ||
err(function(){ | ||
'asd'.should.be.empty; | ||
}, "expected 'asd' to be empty"); | ||
err(function(){ | ||
'asd'.should.have.property('length', 4); | ||
}, "expected 'asd' to have a property 'length' of 4, but got 3"); | ||
err(function(){ | ||
''.should.not.be.empty; | ||
}, "expected '' not to be empty"); | ||
}); | ||
err(function(){ | ||
'asd'.should.not.have.property('length', 3); | ||
}, "expected 'asd' to not have a property 'length' of 3"); | ||
test('property(name)', function(){ | ||
'test'.should.have.property('length'); | ||
(4).should.not.have.property('length'); | ||
err(function(){ | ||
'asd'.should.not.have.property('foo', 3); | ||
}, "'asd' has no property 'foo'"); | ||
err(function(){ | ||
'asd'.should.have.property('foo'); | ||
}, "expected 'asd' to have a property 'foo'"); | ||
}); | ||
err(function(){ | ||
'asd'.should.have.property('constructor', Number); | ||
}, "expected 'asd' to have a property 'constructor' of [Function: Number], but got [Function: String]"); | ||
}, | ||
test('property(name, val)', function(){ | ||
'test'.should.have.property('length', 4); | ||
'asd'.should.have.property('constructor', String); | ||
'test ownProperty(name)': function(){ | ||
'test'.should.have.ownProperty('length'); | ||
'test'.should.haveOwnProperty('length'); | ||
({ length: 12 }).should.have.ownProperty('length'); | ||
err(function(){ | ||
'asd'.should.have.property('length', 4); | ||
}, "expected 'asd' to have a property 'length' of 4, but got 3"); | ||
err(function(){ | ||
({ length: 12 }).should.not.have.ownProperty('length'); | ||
}, "expected { length: 12 } to not have own property 'length'"); | ||
}, | ||
err(function(){ | ||
'asd'.should.not.have.property('length', 3); | ||
}, "expected 'asd' to not have a property 'length' of 3"); | ||
'test string()': function(){ | ||
'foobar'.should.contain.string('bar'); | ||
'foobar'.should.contain.string('foo'); | ||
'foobar'.should.not.contain.string('baz'); | ||
err(function(){ | ||
'asd'.should.not.have.property('foo', 3); | ||
}, "'asd' has no property 'foo'"); | ||
err(function(){ | ||
(3).should.contain.string('baz'); | ||
}, "expected 3 to be a string"); | ||
err(function(){ | ||
'asd'.should.have.property('constructor', Number); | ||
}, "expected 'asd' to have a property 'constructor' of [Function: Number], but got [Function: String]"); | ||
}); | ||
err(function(){ | ||
'foobar'.should.contain.string('baz'); | ||
}, "expected 'foobar' to contain 'baz'"); | ||
test('ownProperty(name)', function(){ | ||
'test'.should.have.ownProperty('length'); | ||
'test'.should.haveOwnProperty('length'); | ||
({ length: 12 }).should.have.ownProperty('length'); | ||
err(function(){ | ||
'foobar'.should.not.contain.string('bar'); | ||
}, "expected 'foobar' to not contain 'bar'"); | ||
}, | ||
err(function(){ | ||
({ length: 12 }).should.not.have.ownProperty('length'); | ||
}, "expected { length: 12 } to not have own property 'length'"); | ||
}); | ||
'test include()': function(){ | ||
['foo', 'bar'].should.include('foo'); | ||
['foo', 'bar'].should.include('foo'); | ||
['foo', 'bar'].should.include('bar'); | ||
[1,2].should.include(1); | ||
['foo', 'bar'].should.not.include('baz'); | ||
['foo', 'bar'].should.not.include(1); | ||
test('string()', function(){ | ||
'foobar'.should.contain.string('bar'); | ||
'foobar'.should.contain.string('foo'); | ||
'foobar'.should.not.contain.string('baz'); | ||
err(function(){ | ||
['foo'].should.include('bar'); | ||
}, "expected [ 'foo' ] to include 'bar'"); | ||
err(function(){ | ||
(3).should.contain.string('baz'); | ||
}, "expected 3 to be a string"); | ||
err(function(){ | ||
['bar', 'foo'].should.not.include('foo'); | ||
}, "expected [ 'bar', 'foo' ] to not include 'foo'"); | ||
}, | ||
err(function(){ | ||
'foobar'.should.contain.string('baz'); | ||
}, "expected 'foobar' to contain 'baz'"); | ||
'test keys(array)': function(){ | ||
({ foo: 1 }).should.have.keys(['foo']); | ||
({ foo: 1, bar: 2 }).should.have.keys(['foo', 'bar']); | ||
({ foo: 1, bar: 2 }).should.have.keys('foo', 'bar'); | ||
({ foo: 1, bar: 2, baz: 3 }).should.contain.keys('foo', 'bar'); | ||
({ foo: 1, bar: 2, baz: 3 }).should.contain.keys('bar', 'foo'); | ||
({ foo: 1, bar: 2, baz: 3 }).should.contain.keys('baz'); | ||
err(function(){ | ||
'foobar'.should.not.contain.string('bar'); | ||
}, "expected 'foobar' to not contain 'bar'"); | ||
}); | ||
({ 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']); | ||
test('include()', function(){ | ||
['foo', 'bar'].should.include('foo'); | ||
['foo', 'bar'].should.include('foo'); | ||
['foo', 'bar'].should.include('bar'); | ||
[1,2].should.include(1); | ||
['foo', 'bar'].should.not.include('baz'); | ||
['foo', 'bar'].should.not.include(1); | ||
({ 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'); | ||
err(function(){ | ||
['foo'].should.include('bar'); | ||
}, "expected [ 'foo' ] to include 'bar'"); | ||
err(function(){ | ||
({ foo: 1 }).should.have.keys(); | ||
}, "keys required"); | ||
err(function(){ | ||
['bar', 'foo'].should.not.include('foo'); | ||
}, "expected [ 'bar', 'foo' ] to not include 'foo'"); | ||
}); | ||
err(function(){ | ||
({ foo: 1 }).should.have.keys([]); | ||
}, "keys required"); | ||
test('keys(array)', function(){ | ||
({ foo: 1 }).should.have.keys(['foo']); | ||
({ foo: 1, bar: 2 }).should.have.keys(['foo', 'bar']); | ||
({ foo: 1, bar: 2 }).should.have.keys('foo', 'bar'); | ||
({ foo: 1, bar: 2, baz: 3 }).should.contain.keys('foo', 'bar'); | ||
({ foo: 1, bar: 2, baz: 3 }).should.contain.keys('bar', 'foo'); | ||
({ foo: 1, bar: 2, baz: 3 }).should.contain.keys('baz'); | ||
err(function(){ | ||
({ foo: 1 }).should.not.have.keys([]); | ||
}, "keys required"); | ||
({ 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']); | ||
err(function(){ | ||
({ foo: 1 }).should.contain.keys([]); | ||
}, "keys required"); | ||
({ 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'); | ||
err(function(){ | ||
({ foo: 1 }).should.have.keys(['bar']); | ||
}, "expected { foo: 1 } to have key 'bar'"); | ||
err(function(){ | ||
({ foo: 1 }).should.have.keys(); | ||
}, "keys required"); | ||
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([]); | ||
}, "keys required"); | ||
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([]); | ||
}, "keys required"); | ||
err(function(){ | ||
({ foo: 1 }).should.not.have.keys(['foo']); | ||
}, "expected { foo: 1 } to not have key 'foo'"); | ||
err(function(){ | ||
({ foo: 1 }).should.contain.keys([]); | ||
}, "keys required"); | ||
err(function(){ | ||
({ foo: 1 }).should.not.have.keys(['foo']); | ||
}, "expected { foo: 1 } to not have key 'foo'"); | ||
err(function(){ | ||
({ foo: 1 }).should.have.keys(['bar']); | ||
}, "expected { foo: 1 } to have key 'bar'"); | ||
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.have.keys(['bar', 'baz']); | ||
}, "expected { foo: 1 } to have keys 'bar', and 'baz'"); | ||
err(function(){ | ||
({ foo: 1 }).should.not.contain.keys(['foo']); | ||
}, "expected { foo: 1 } to not contain key 'foo'"); | ||
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.contain.keys('foo', 'bar'); | ||
}, "expected { foo: 1 } to contain keys 'foo', and 'bar'"); | ||
}, | ||
err(function(){ | ||
({ foo: 1 }).should.not.have.keys(['foo']); | ||
}, "expected { foo: 1 } to not have key 'foo'"); | ||
'test throw': function () { | ||
var goodFn = function () { 1==1; } | ||
, badFn = function () { throw new Error('testing'); } | ||
, refErrFn = function () { throw new ReferenceError(); }; | ||
err(function(){ | ||
({ foo: 1 }).should.not.have.keys(['foo']); | ||
}, "expected { foo: 1 } to not have key 'foo'"); | ||
(goodFn).should.not.throw(); | ||
(goodFn).should.not.throw(Error); | ||
(badFn).should.throw(); | ||
(badFn).should.throw(Error); | ||
(badFn).should.not.throw(ReferenceError); | ||
(refErrFn).should.throw(); | ||
(refErrFn).should.throw(ReferenceError); | ||
(refErrFn).should.not.throw(Error); | ||
(refErrFn).should.not.throw(TypeError); | ||
err(function(){ | ||
({ foo: 1, bar: 2 }).should.not.have.keys(['foo', 'bar']); | ||
}, "expected { foo: 1, bar: 2 } to not have keys 'foo', and 'bar'"); | ||
should.throw(badFn); | ||
should.throw(refErrFn, ReferenceError); | ||
should.not.throw(goodFn); | ||
should.not.throw(badFn, ReferenceError); | ||
err(function(){ | ||
({ foo: 1 }).should.not.contain.keys(['foo']); | ||
}, "expected { foo: 1 } to not contain key 'foo'"); | ||
err(function(){ | ||
(goodFn).should.throw(); | ||
}, "expected [Function] to throw an error"); | ||
err(function(){ | ||
({ foo: 1 }).should.contain.keys('foo', 'bar'); | ||
}, "expected { foo: 1 } to contain keys 'foo', and 'bar'"); | ||
}); | ||
err(function(){ | ||
(goodFn).should.throw(ReferenceError); | ||
}, "expected [Function] to throw ReferenceError"); | ||
test('throw', function () { | ||
var goodFn = function () { 1==1; } | ||
, badFn = function () { throw new Error('testing'); } | ||
, refErrFn = function () { throw new ReferenceError(); }; | ||
err(function(){ | ||
(badFn).should.not.throw(); | ||
}, "expected [Function] to not throw an error"); | ||
(goodFn).should.not.throw(); | ||
(goodFn).should.not.throw(Error); | ||
(badFn).should.throw(); | ||
(badFn).should.throw(Error); | ||
(badFn).should.not.throw(ReferenceError); | ||
(refErrFn).should.throw(); | ||
(refErrFn).should.throw(ReferenceError); | ||
(refErrFn).should.not.throw(Error); | ||
(refErrFn).should.not.throw(TypeError); | ||
err(function(){ | ||
(badFn).should.throw(ReferenceError); | ||
}, "expected [Function] to throw ReferenceError but a Error was thrown"); | ||
should.throw(badFn); | ||
should.throw(refErrFn, ReferenceError); | ||
should.not.throw(goodFn); | ||
should.not.throw(badFn, ReferenceError); | ||
err(function(){ | ||
(badFn).should.not.throw(Error); | ||
}, "expected [Function] to not throw Error"); | ||
err(function(){ | ||
(goodFn).should.throw(); | ||
}, "expected [Function] to throw an error"); | ||
err(function(){ | ||
(refErrFn).should.not.throw(ReferenceError); | ||
}, "expected [Function] to not throw ReferenceError"); | ||
err(function(){ | ||
(goodFn).should.throw(ReferenceError); | ||
}, "expected [Function] to throw ReferenceError"); | ||
err(function(){ | ||
(refErrFn).should.throw(Error); | ||
}, "expected [Function] to throw Error but a ReferenceError was thrown"); | ||
} | ||
} | ||
}; | ||
err(function(){ | ||
(badFn).should.not.throw(); | ||
}, "expected [Function] to not throw an error"); | ||
err(function(){ | ||
(badFn).should.throw(ReferenceError); | ||
}, "expected [Function] to throw ReferenceError but a Error was thrown"); | ||
err(function(){ | ||
(badFn).should.not.throw(Error); | ||
}, "expected [Function] to not throw Error"); | ||
err(function(){ | ||
(refErrFn).should.not.throw(ReferenceError); | ||
}, "expected [Function] to not throw ReferenceError"); | ||
err(function(){ | ||
(refErrFn).should.throw(Error); | ||
}, "expected [Function] to throw Error but a ReferenceError was thrown"); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
131069
4174