@@ -9,7 +9,7 @@ var { Assert } = ChromeUtils.importESModule(
9
9
"resource://testing-common/Assert.sys.mjs"
10
10
) ;
11
11
12
- function run_test ( ) {
12
+ add_task ( function test_basic_asserts ( ) {
13
13
let assert = new Assert ( ) ;
14
14
15
15
function makeBlock ( f , ...args ) {
@@ -378,34 +378,49 @@ function run_test() {
378
378
assert . equal ( message , "AssertionError: 1 >= 2" ) ;
379
379
380
380
assert . less ( 1 , 2 ) ;
381
- try {
382
- assert . less ( 2 , 2 ) ;
383
- } catch ( e ) {
384
- message = e . toString ( ) . split ( "\n" ) [ 0 ] ;
385
- }
386
- assert . equal ( message , "AssertionError: 2 < 2" ) ;
381
+ assert . throws (
382
+ ( ) => assert . less ( 2 , 2 ) ,
383
+ e => e == "AssertionError: 2 < 2"
384
+ ) ;
387
385
388
386
assert . lessOrEqual ( 2 , 2 ) ;
389
- try {
390
- assert . lessOrEqual ( 2 , 1 ) ;
391
- } catch ( e ) {
392
- message = e . toString ( ) . split ( "\n" ) [ 0 ] ;
393
- }
394
- assert . equal ( message , "AssertionError: 2 <= 1" ) ;
387
+ assert . throws (
388
+ ( ) => assert . lessOrEqual ( 2 , 1 ) ,
389
+ e => e == "AssertionError: 2 <= 1"
390
+ ) ;
395
391
396
- try {
397
- assert . greater ( NaN , 0 ) ;
398
- } catch ( e ) {
399
- message = e . toString ( ) . split ( "\n" ) [ 0 ] ;
400
- }
401
- assert . equal ( message , "AssertionError: 'NaN' is not a number" ) ;
392
+ assert . throws (
393
+ ( ) => assert . greater ( NaN , 0 ) ,
394
+ e => e == "AssertionError: 'NaN' is not a number or date."
395
+ ) ;
402
396
403
- try {
404
- assert . greater ( 0 , NaN ) ;
405
- } catch ( e ) {
406
- message = e . toString ( ) . split ( "\n" ) [ 0 ] ;
407
- }
408
- assert . equal ( message , "AssertionError: 'NaN' is not a number" ) ;
397
+ assert . throws (
398
+ ( ) => assert . greater ( 0 , NaN ) ,
399
+ e => e == "AssertionError: 'NaN' is not a number or date."
400
+ ) ;
401
+
402
+ let now = new Date ( ) ;
403
+ let firefoxReleaseDate = new Date ( "2004-11-09" ) ;
404
+ assert . less ( firefoxReleaseDate , now ) ;
405
+ assert . throws (
406
+ ( ) => assert . less ( now , now ) ,
407
+ e => e == `AssertionError: "${ now . toJSON ( ) } " < "${ now . toJSON ( ) } "`
408
+ ) ;
409
+
410
+ assert . lessOrEqual ( now , now ) ;
411
+ assert . greaterOrEqual ( now , now ) ;
412
+ assert . throws (
413
+ ( ) => assert . greaterOrEqual ( firefoxReleaseDate , now ) ,
414
+ e =>
415
+ e ==
416
+ `AssertionError: "${ firefoxReleaseDate . toJSON ( ) } " >= "${ now . toJSON ( ) } "`
417
+ ) ;
418
+
419
+ // Invalid date:
420
+ assert . throws (
421
+ ( ) => assert . greater ( firefoxReleaseDate , new Date ( "invalid" ) ) ,
422
+ e => e == "AssertionError: 'Invalid Date' is not a number or date."
423
+ ) ;
409
424
410
425
/* ---- stringMatches ---- */
411
426
assert . stringMatches ( "hello world" , / l l o \s / ) ;
@@ -429,9 +444,7 @@ function run_test() {
429
444
( ) => assert . stringContains ( 5 , "foo" ) ,
430
445
/ ^ A s s e r t i o n E r r o r : E x p e c t e d a s t r i n g f o r b o t h l h s a n d r h s , b u t e i t h e r " 5 " o r " f o o " i s n o t a s t r i n g ./
431
446
) ;
432
-
433
- run_next_test ( ) ;
434
- }
447
+ } ) ;
435
448
436
449
add_task ( async function test_rejects ( ) {
437
450
let assert = new Assert ( ) ;
0 commit comments