1
1
/**
2
- * QUnit v1.8 .0 - A JavaScript Unit Testing Framework
2
+ * QUnit v1.9 .0 - A JavaScript Unit Testing Framework
3
3
*
4
4
* http://docs.jquery.com/QUnit
5
5
*
@@ -403,6 +403,8 @@ QUnit = {
403
403
QUnit . assert = {
404
404
/**
405
405
* Asserts rough true-ish result.
406
+ * @name ok
407
+ * @function
406
408
* @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" );
407
409
*/
408
410
ok : function ( result , msg ) {
@@ -437,36 +439,59 @@ QUnit.assert = {
437
439
/**
438
440
* Assert that the first two arguments are equal, with an optional message.
439
441
* Prints out both actual and expected values.
442
+ * @name equal
443
+ * @function
440
444
* @example equal( format( "Received {0} bytes.", 2), "Received 2 bytes.", "format() replaces {0} with next argument" );
441
445
*/
442
446
equal : function ( actual , expected , message ) {
443
447
QUnit . push ( expected == actual , actual , expected , message ) ;
444
448
} ,
445
449
450
+ /**
451
+ * @name notEqual
452
+ * @function
453
+ */
446
454
notEqual : function ( actual , expected , message ) {
447
455
QUnit . push ( expected != actual , actual , expected , message ) ;
448
456
} ,
449
457
458
+ /**
459
+ * @name deepEqual
460
+ * @function
461
+ */
450
462
deepEqual : function ( actual , expected , message ) {
451
463
QUnit . push ( QUnit . equiv ( actual , expected ) , actual , expected , message ) ;
452
464
} ,
453
465
466
+ /**
467
+ * @name notDeepEqual
468
+ * @function
469
+ */
454
470
notDeepEqual : function ( actual , expected , message ) {
455
471
QUnit . push ( ! QUnit . equiv ( actual , expected ) , actual , expected , message ) ;
456
472
} ,
457
473
474
+ /**
475
+ * @name strictEqual
476
+ * @function
477
+ */
458
478
strictEqual : function ( actual , expected , message ) {
459
479
QUnit . push ( expected === actual , actual , expected , message ) ;
460
480
} ,
461
481
482
+ /**
483
+ * @name notStrictEqual
484
+ * @function
485
+ */
462
486
notStrictEqual : function ( actual , expected , message ) {
463
487
QUnit . push ( expected !== actual , actual , expected , message ) ;
464
488
} ,
465
489
466
- raises : function ( block , expected , message ) {
490
+ throws : function ( block , expected , message ) {
467
491
var actual ,
468
492
ok = false ;
469
493
494
+ // 'expected' is optional
470
495
if ( typeof expected === "string" ) {
471
496
message = expected ;
472
497
expected = null ;
@@ -494,18 +519,29 @@ QUnit.assert = {
494
519
} else if ( expected . call ( { } , actual ) === true ) {
495
520
ok = true ;
496
521
}
497
- }
498
522
499
- QUnit . push ( ok , actual , null , message ) ;
523
+ QUnit . push ( ok , actual , null , message ) ;
524
+ } else {
525
+ QUnit . pushFailure ( message , null , 'No exception was thrown.' ) ;
526
+ }
500
527
}
501
528
} ;
502
529
503
- // @deprecated : Kept assertion helpers in root for backwards compatibility
530
+ /**
531
+ * @deprecate since 1.8.0
532
+ * Kept assertion helpers in root for backwards compatibility
533
+ */
504
534
extend ( QUnit , QUnit . assert ) ;
505
535
506
536
/**
507
- * @deprecated : Kept for backwards compatibility
508
- * next step: remove entirely
537
+ * @deprecated since 1.9.0
538
+ * Kept global "raises()" for backwards compatibility
539
+ */
540
+ QUnit . raises = QUnit . assert . throws ;
541
+
542
+ /**
543
+ * @deprecated since 1.0.0, replaced with error pushes since 1.3.0
544
+ * Kept to avoid TypeErrors for undefined methods.
509
545
*/
510
546
QUnit . equals = function ( ) {
511
547
QUnit . push ( false , false , false , "QUnit.equals has been deprecated since 2009 (e88049a0), use QUnit.equal instead" ) ;
@@ -549,7 +585,20 @@ config = {
549
585
// when enabled, all tests must call expect()
550
586
requireExpects : false ,
551
587
552
- urlConfig : [ "noglobals" , "notrycatch" ] ,
588
+ // add checkboxes that are persisted in the query-string
589
+ // when enabled, the id is set to `true` as a `QUnit.config` property
590
+ urlConfig : [
591
+ {
592
+ id : "noglobals" ,
593
+ label : "Check for Globals" ,
594
+ tooltip : "Enabling this will test if any test introduces new properties on the `window` object. Stored as query-strings."
595
+ } ,
596
+ {
597
+ id : "notrycatch" ,
598
+ label : "No try-catch" ,
599
+ tooltip : "Enabling this will run tests outside of a try-catch block. Makes debugging exceptions in IE reasonable. Stored as query-strings."
600
+ }
601
+ ] ,
553
602
554
603
// logging callback queues
555
604
begin : [ ] ,
@@ -770,7 +819,7 @@ extend( QUnit, {
770
819
} ) ;
771
820
} ,
772
821
773
- pushFailure : function ( message , source ) {
822
+ pushFailure : function ( message , source , actual ) {
774
823
if ( ! config . current ) {
775
824
throw new Error ( "pushFailure() assertion outside test context, was " + sourceFromStacktrace ( 2 ) ) ;
776
825
}
@@ -781,15 +830,23 @@ extend( QUnit, {
781
830
message : message
782
831
} ;
783
832
784
- message = escapeInnerText ( message ) || "error" ;
833
+ message = escapeInnerText ( message ) || "error" ;
785
834
message = "<span class='test-message'>" + message + "</span>" ;
786
835
output = message ;
787
836
837
+ output += "<table>" ;
838
+
839
+ if ( actual ) {
840
+ output += "<tr class='test-actual'><th>Result: </th><td><pre>" + escapeInnerText ( actual ) + "</pre></td></tr>" ;
841
+ }
842
+
788
843
if ( source ) {
789
844
details . source = source ;
790
- output += "<table>< tr class='test-source'><th>Source: </th><td><pre>" + escapeInnerText ( source ) + "</pre></td></tr></table >" ;
845
+ output += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeInnerText ( source ) + "</pre></td></tr>" ;
791
846
}
792
847
848
+ output += "</table>" ;
849
+
793
850
runLoggingCallbacks ( "log" , QUnit , details ) ;
794
851
795
852
config . current . assertions . push ( {
@@ -859,7 +916,7 @@ QUnit.load = function() {
859
916
runLoggingCallbacks ( "begin" , QUnit , { } ) ;
860
917
861
918
// Initialize the config, saving the execution queue
862
- var banner , filter , i , label , len , main , ol , toolbar , userAgent , val ,
919
+ var banner , filter , i , label , len , main , ol , toolbar , userAgent , val , urlConfigCheckboxes ,
863
920
urlConfigHtml = "" ,
864
921
oldconfig = extend ( { } , config ) ;
865
922
@@ -872,8 +929,15 @@ QUnit.load = function() {
872
929
873
930
for ( i = 0 ; i < len ; i ++ ) {
874
931
val = config . urlConfig [ i ] ;
875
- config [ val ] = QUnit . urlParams [ val ] ;
876
- urlConfigHtml += "<label><input name='" + val + "' type='checkbox'" + ( config [ val ] ? " checked='checked'" : "" ) + ">" + val + "</label>" ;
932
+ if ( typeof val === "string" ) {
933
+ val = {
934
+ id : val ,
935
+ label : val ,
936
+ tooltip : "[no tooltip available]"
937
+ } ;
938
+ }
939
+ config [ val . id ] = QUnit . urlParams [ val . id ] ;
940
+ urlConfigHtml += "<input id='qunit-urlconfig-" + val . id + "' name='" + val . id + "' type='checkbox'" + ( config [ val . id ] ? " checked='checked'" : "" ) + " title='" + val . tooltip + "'><label for='qunit-urlconfig-" + val . id + "' title='" + val . tooltip + "'>" + val . label + "</label>" ;
877
941
}
878
942
879
943
// `userAgent` initialized at top of scope
@@ -885,12 +949,7 @@ QUnit.load = function() {
885
949
// `banner` initialized at top of scope
886
950
banner = id ( "qunit-header" ) ;
887
951
if ( banner ) {
888
- banner . innerHTML = "<a href='" + QUnit . url ( { filter : undefined } ) + "'>" + banner . innerHTML + "</a> " + urlConfigHtml ;
889
- addEvent ( banner , "change" , function ( event ) {
890
- var params = { } ;
891
- params [ event . target . name ] = event . target . checked ? true : undefined ;
892
- window . location = QUnit . url ( params ) ;
893
- } ) ;
952
+ banner . innerHTML = "<a href='" + QUnit . url ( { filter : undefined , module : undefined , testNumber : undefined } ) + "'>" + banner . innerHTML + "</a> " ;
894
953
}
895
954
896
955
// `toolbar` initialized at top of scope
@@ -931,8 +990,18 @@ QUnit.load = function() {
931
990
// `label` initialized at top of scope
932
991
label = document . createElement ( "label" ) ;
933
992
label . setAttribute ( "for" , "qunit-filter-pass" ) ;
993
+ label . setAttribute ( "title" , "Only show tests and assertons that fail. Stored in sessionStorage." ) ;
934
994
label . innerHTML = "Hide passed tests" ;
935
995
toolbar . appendChild ( label ) ;
996
+
997
+ urlConfigCheckboxes = document . createElement ( 'span' ) ;
998
+ urlConfigCheckboxes . innerHTML = urlConfigHtml ;
999
+ addEvent ( urlConfigCheckboxes , "change" , function ( event ) {
1000
+ var params = { } ;
1001
+ params [ event . target . name ] = event . target . checked ? true : undefined ;
1002
+ window . location = QUnit . url ( params ) ;
1003
+ } ) ;
1004
+ toolbar . appendChild ( urlConfigCheckboxes ) ;
936
1005
}
937
1006
938
1007
// `main` initialized at top of scope
@@ -1051,14 +1120,14 @@ function done() {
1051
1120
function validTest ( test ) {
1052
1121
var include ,
1053
1122
filter = config . filter && config . filter . toLowerCase ( ) ,
1054
- module = config . module ,
1123
+ module = config . module && config . module . toLowerCase ( ) ,
1055
1124
fullName = ( test . module + ": " + test . testName ) . toLowerCase ( ) ;
1056
1125
1057
1126
if ( config . testNumber ) {
1058
1127
return test . testNumber === config . testNumber ;
1059
1128
}
1060
1129
1061
- if ( module && test . module !== module ) {
1130
+ if ( module && ( ! test . module || test . module . toLowerCase ( ) !== module ) ) {
1062
1131
return false ;
1063
1132
}
1064
1133
0 commit comments