Skip to content

Commit

Permalink
Assert: Add type check to assert.async()
Browse files Browse the repository at this point in the history
Fixes #1721.
  • Loading branch information
zixinyin committed Aug 21, 2023
1 parent 8444f81 commit ddc5830
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ class Assert {

// Create a new async pause and return a new function that can release the pause.
async (count) {
const requiredCalls = count === undefined ? 1 : count;
if (count === undefined) {
count = 1;
} else if (typeof count !== 'number') {
throw new TypeError('async takes number as an input');
}
const requiredCalls = count;
return this.test.internalStop(requiredCalls);
}

Expand Down
9 changes: 9 additions & 0 deletions test/main/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ QUnit.module('assert.async', function () {
done();
});

QUnit.test('fails if using non-numeric as an input', function (assert) {
assert.throws(
function () {
assert.async('an invalid string input');
},
new TypeError('async takes number as an input')
);
});

QUnit.test('fails if called more than specified count', function (assert) {
// Having an outer async flow in this test avoids the need to manually modify QUnit internals
// in order to avoid post-`done` assertions causing additional failures
Expand Down

0 comments on commit ddc5830

Please sign in to comment.