File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ /* global axe*/
2+
3+ /**
4+ * If the first argument is falsey, throw an error using the second argument as a message.
5+ * @param {boolean } bool
6+ * @param {string } message
7+ */
8+ axe . utils . assert = function assert ( bool , message ) {
9+ if ( ! bool ) {
10+ throw new Error ( message )
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ describe ( 'axe.utils.assert' , function ( ) {
2+ it ( 'does nothing when passed a truthy value' , function ( ) {
3+ assert . doesNotThrow ( function ( ) {
4+ axe . utils . assert ( true )
5+ axe . utils . assert ( 'foo' )
6+ axe . utils . assert ( 123 )
7+ axe . utils . assert ( [ ] )
8+ axe . utils . assert ( { } )
9+ } )
10+ } )
11+
12+ it ( 'throws an error when passed a falsey value' , function ( ) {
13+ assert . throws ( function ( ) {
14+ axe . utils . assert ( false )
15+ } )
16+ assert . throws ( function ( ) {
17+ axe . utils . assert ( 0 )
18+ } )
19+ assert . throws ( function ( ) {
20+ axe . utils . assert ( null )
21+ } )
22+ assert . throws ( function ( ) {
23+ axe . utils . assert ( undefined )
24+ } )
25+ } )
26+
27+ it ( 'sets second argument as the error message' , function ( ) {
28+ var message = 'Something went wrong'
29+ try {
30+ axe . utils . assert ( false , message )
31+ } catch ( e ) {
32+ assert . instanceOf ( e , Error )
33+ assert . equal ( e . message , message )
34+ }
35+ } )
36+ } )
You can’t perform that action at this time.
0 commit comments