Skip to content

Commit

Permalink
Add a bunch of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed Jan 24, 2024
1 parent 8256804 commit 0eebc39
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
34 changes: 34 additions & 0 deletions test/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down
37 changes: 36 additions & 1 deletion test/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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.");

Expand Down
2 changes: 2 additions & 0 deletions test/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 0eebc39

Please sign in to comment.