diff --git a/test/assert.js b/test/assert.js index 912aa18f..db2e1025 100644 --- a/test/assert.js +++ b/test/assert.js @@ -139,6 +139,20 @@ describe('assert', function () { assert.typeOf('test', 'string'); assert.typeOf(true, 'boolean'); assert.typeOf(5, 'number'); + + assert.typeOf(() => {}, 'function'); + assert.typeOf(function() {}, 'function'); + assert.typeOf(async function() {}, 'asyncfunction'); + assert.typeOf(function*() {}, 'generatorfunction'); + assert.typeOf(async function*() {}, 'asyncgeneratorfunction'); + + err(function () { + assert.typeOf(5, 'function', 'blah'); + }, "blah: expected 5 to be a function"); + + err(function () { + assert.typeOf(function() {}, 'asyncfunction', 'blah'); + }, "blah: expected [Function] to be an asyncfunction"); if (typeof Symbol === 'function') { assert.typeOf(Symbol(), 'symbol'); @@ -151,10 +165,20 @@ describe('assert', function () { it('notTypeOf', function () { assert.notTypeOf('test', 'number'); + + assert.notTypeOf(() => {}, 'string'); + assert.notTypeOf(function() {}, 'string'); + assert.notTypeOf(async function() {}, 'string'); + assert.notTypeOf(function*() {}, 'string'); + assert.notTypeOf(async function*() {}, 'string'); err(function () { assert.notTypeOf(5, 'number', 'blah'); }, "blah: expected 5 not to be a number"); + + err(function () { + assert.notTypeOf(() => {}, 'function', 'blah'); + }, "blah: expected [Function] not to be a function"); }); it('instanceOf', function() { @@ -547,6 +571,16 @@ describe('assert', function () { assert.isCallable({}, 'blah'); }, "blah: expected {} to be a callable function"); }); + + it('isNotCallable', function() { + assert.isNotCallable(false); + assert.isNotCallable(10); + assert.isNotCallable('string'); + + err(function () { + assert.isNotCallable(function() {}, 'blah'); + }, "blah: expected [Function] not to be a callable function"); + }); it('isNotFunction', function () { assert.isNotFunction(5); diff --git a/test/expect.js b/test/expect.js index e1d54a4b..d5247655 100644 --- a/test/expect.js +++ b/test/expect.js @@ -391,6 +391,29 @@ describe('expect', function () { expect(function*() {}).to.be.callable; expect(async function*() {}).to.be.callable; + expect('foobar').to.not.be.callable; + + err(function(){ + expect('foobar', 'blah').to.be.callable; + }, "blah: expected 'foobar' to be a callable function"); + + err(function(){ + expect(function() {}, 'blah').to.not.be.callable; + }, "blah: expected [Function] not to be a callable function"); + }); + + it('function', function() { + expect(function() {}).to.be.a('function'); + expect(async function() {}).to.be.a('function'); + expect(function*() {}).to.be.a('function'); + expect(async function*() {}).to.be.a('function'); + + expect('foobar').to.not.be.a('function'); + + err(function(){ + expect('foobar').to.be.a('function', 'blah'); + }, "blah: expected 'foobar' to be a function"); + err(function(){ expect(function() {}).to.not.be.a('function', 'blah'); }, "blah: expected [Function] not to be a function"); @@ -404,6 +427,10 @@ describe('expect', function () { expect(async function() {}).to.be.a('AsyncFunction'); expect(async function*() {}).to.be.a('AsyncFunction'); + err(function(){ + expect('foobar').to.be.a('asyncfunction', 'blah'); + }, "blah: expected 'foobar' to be an asyncfunction"); + err(function(){ expect(async function() {}).to.not.be.a('asyncfunction', 'blah'); }, "blah: expected [AsyncFunction] not to be an asyncfunction"); @@ -417,6 +444,10 @@ describe('expect', function () { expect(function*() {}).to.be.a('generatorFunction'); expect(async function*() {}).to.be.a('generatorFunction'); + err(function(){ + expect('foobar').to.be.a('generatorfunction', 'blah'); + }, "blah: expected 'foobar' to be a generatorfunction"); + err(function(){ expect(function*() {}).to.not.be.a('generatorfunction', 'blah'); }, "blah: expected [GeneratorFunction] not to be a generatorfunction"); @@ -429,6 +460,10 @@ describe('expect', function () { it('asyncGeneratorFunction', function() { expect(async function*() {}).to.be.a('asyncGeneratorFunction'); + err(function(){ + expect(async function() {}, 'blah').to.be.a('asyncgeneratorfunction'); + }, "blah: expected [AsyncFunction] to be an asyncgeneratorfunction"); + err(function(){ expect(async function*() {}, 'blah').to.not.be.a('asyncgeneratorfunction'); }, "blah: expected [AsyncGeneratorFunction] not to be an asyncgeneratorfunction"); @@ -456,8 +491,8 @@ describe('expect', function () { err(function(){ expect(new Foo(), 'blah').to.an.instanceof(1); }, "blah: The instanceof assertion needs a constructor but Number was given."); - err(function(){ + err(function(){ expect(new Foo()).to.an.instanceof('batman'); }, "The instanceof assertion needs a constructor but String was given."); diff --git a/test/should.js b/test/should.js index 17429961..b1575141 100644 --- a/test/should.js +++ b/test/should.js @@ -442,6 +442,8 @@ describe('should', function() { ({}).should.be.a('object'); ([]).should.be.a('array'); (function() {}).should.be.a('function'); + (async function*() {}).should.be.a('function'); + (async function() {}).should.be.a('asyncfunction'); if (typeof Symbol === 'function') { Symbol().should.be.a('symbol');