-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2bef161
commit 2f10d24
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* global axe*/ | ||
|
||
/** | ||
* If the first argument is falsey, throw an error using the second argument as a message. | ||
* @param {boolean} bool | ||
* @param {string} message | ||
*/ | ||
axe.utils.assert = function assert (bool, message) { | ||
if (!bool) { | ||
throw new Error(message) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
describe('axe.utils.assert', function () { | ||
it('does nothing when passed a truthy value', function () { | ||
assert.doesNotThrow(function () { | ||
axe.utils.assert(true) | ||
axe.utils.assert('foo') | ||
axe.utils.assert(123) | ||
axe.utils.assert([]) | ||
axe.utils.assert({}) | ||
}) | ||
}) | ||
|
||
it('throws an error when passed a falsey value', function () { | ||
assert.throws(function () { | ||
axe.utils.assert(false) | ||
}) | ||
assert.throws(function () { | ||
axe.utils.assert(0) | ||
}) | ||
assert.throws(function () { | ||
axe.utils.assert(null) | ||
}) | ||
assert.throws(function () { | ||
axe.utils.assert(undefined) | ||
}) | ||
}) | ||
|
||
it('sets second argument as the error message', function () { | ||
var message = 'Something went wrong' | ||
try { | ||
axe.utils.assert(false, message) | ||
} catch (e) { | ||
assert.instanceOf(e, Error) | ||
assert.equal(e.message, message) | ||
} | ||
}) | ||
}) |