Skip to content

Commit 2f513d8

Browse files
committed
introduce isAsyncFunction and isNotAsyncFunction assertions
1 parent 9d8c5bf commit 2f513d8

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

lib/chai/interface/assert.js

+36
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,42 @@ assert.isNotFunction = function (val, msg) {
590590
new Assertion(val, msg, assert.isNotFunction, true).to.not.be.a('function');
591591
};
592592

593+
/**
594+
* ### .isAsyncFunction(value, [message])
595+
*
596+
* Asserts that `value` is a async function.
597+
*
598+
* async function serveTea() { return 'cup of tea'; };
599+
* assert.isAsyncFunction(serveTea, 'great, we can have tea now');
600+
*
601+
* @name isAsyncFunction
602+
* @param {Mixed} value
603+
* @param {String} message
604+
* @namespace Assert
605+
* @api public
606+
*/
607+
assert.isAsyncFunction = function (val, msg) {
608+
new Assertion(val, msg, assert.isAsyncFunction, true).to.be.a('asyncfunction');
609+
};
610+
611+
/**
612+
* ### .isNotAsyncFunction(value, [message])
613+
*
614+
* Asserts that `value` is _not_ a async function.
615+
*
616+
* var serveTea = [ 'heat', 'pour', 'sip' ];
617+
* assert.isNotAsyncFunction(serveTea, 'great, we have listed the steps');
618+
*
619+
* @name isNotAsyncFunction
620+
* @param {Mixed} value
621+
* @param {String} message
622+
* @namespace Assert
623+
* @api public
624+
*/
625+
assert.isNotAsyncFunction = function (val, msg) {
626+
new Assertion(val, msg, assert.isNotAsyncFunction, true).to.not.be.a('asyncfunction');
627+
};
628+
593629
/**
594630
* ### .isObject(value, [message])
595631
*

test/assert.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,6 @@ describe('assert', function () {
524524
it('isFunction', function() {
525525
var func = function() {};
526526
assert.isFunction(func);
527-
528-
async function asyncFunction() {};
529-
assert.isFunction(asyncFunction);
530527

531528
err(function () {
532529
assert.isFunction({}, 'blah');
@@ -540,6 +537,23 @@ describe('assert', function () {
540537
assert.isNotFunction(function () {}, 'blah');
541538
}, "blah: expected [Function] not to be a function");
542539
});
540+
541+
it('isAsyncFunction', function() {
542+
async function func() {};
543+
assert.isAsyncFunction(func);
544+
545+
err(function () {
546+
assert.isAsyncFunction(function () {}, 'blah');
547+
}, "blah: expected [Function] to be an asyncfunction");
548+
});
549+
550+
it('isNotAsyncFunction', function () {
551+
assert.isNotAsyncFunction(5);
552+
553+
err(function () {
554+
assert.isNotAsyncFunction(async function () {}, 'blah');
555+
}, "blah: expected [Function] not to be an asyncfunction");
556+
});
543557

544558
it('isArray', function() {
545559
assert.isArray([]);

0 commit comments

Comments
 (0)