Skip to content

Commit

Permalink
add check for window.assert in unit tests, see #73
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarlow12 committed Jan 9, 2019
1 parent 84934f1 commit d4e6946
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions js/OpenRangeTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,28 @@ define( function( require ) {
QUnit.test( 'setter overrides', function( assert ) {
var openRange = new OpenRange( 1, 10 );
assert.notOk( openRange.setMin( 2 ), 'can set min < max' );
assert.throws( function() { openRange.setMin( 10 ); }, 'cannot set min = max in OpenRange' );
window.assert && assert.throws( function() { openRange.setMin( 10 ); }, 'cannot set min = max in OpenRange' );
openRange = new OpenRange( 1, 10 );
assert.notOk( openRange.setMax( 2 ), 'can set max > min' );
assert.throws( function() { openRange.setMax( 1 ); }, 'cannot set min = max in OpenRange' );
window.assert && assert.throws( function() { openRange.setMax( 1 ); }, 'cannot set min = max in OpenRange' );
} );

QUnit.test( 'assertion failures', function( assert ) {
assert.throws( function() { return new OpenRange( 1, 10, { openMin: false, openMax: false } ); }, 'include both min and max throws an error' );
assert.throws( function() { return new OpenRange( 1, 1, minHalfOpenOptions ); }, 'min open range with min === max throws an error' );
assert.throws( function() { return new OpenRange( 1, 1, maxHalfOpenOptions ); }, 'max open range with min === max throws an error' );
assert.throws( function() { return new OpenRange( 1, 1 ); }, 'full open range with min === max throws an error' );
if ( window.assert ) {
assert.throws( function() { return new OpenRange( 1, 10, { openMin: false, openMax: false } ); }, 'include both min and max throws an error' );
assert.throws( function() { return new OpenRange( 1, 1, minHalfOpenOptions ); }, 'min open range with min === max throws an error' );
assert.throws( function() { return new OpenRange( 1, 1, maxHalfOpenOptions ); }, 'max open range with min === max throws an error' );
assert.throws( function() { return new OpenRange( 1, 1 ); }, 'full open range with min === max throws an error' );

var range = new OpenRange( 1, 10 );
assert.throws( function() { range.setMin( 10 ); }, 'setting min equal to max throws an error' );
range = new OpenRange( 1, 10 );
assert.throws( function() { range.setMin( 11 ); }, 'setting min greater than max throws an error' );
range = new OpenRange( 1, 10 );
assert.throws( function() { range.setMax( 1 ); }, 'setting max equal to min throws an error' );
range = new OpenRange( 1, 10 );
assert.throws( function() { range.setMax( 0 ); }, 'setting max less than min throws an error' );
var range = new OpenRange( 1, 10 );
assert.throws( function() { range.setMin( 10 ); }, 'setting min equal to max throws an error' );
range = new OpenRange( 1, 10 );
assert.throws( function() { range.setMin( 11 ); }, 'setting min greater than max throws an error' );
range = new OpenRange( 1, 10 );
assert.throws( function() { range.setMax( 1 ); }, 'setting max equal to min throws an error' );
range = new OpenRange( 1, 10 );
assert.throws( function() { range.setMax( 0 ); }, 'setting max less than min throws an error' );
}
assert.ok( true );
} );
} );

0 comments on commit d4e6946

Please sign in to comment.