Replacing strictEqual-assertion with a more useful QUnit.push that includes the expec...
authorKrinkle <krinkle@users.mediawiki.org>
Mon, 13 Jun 2011 00:47:15 +0000 (00:47 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Mon, 13 Jun 2011 00:47:15 +0000 (00:47 +0000)
This way we end up with:
"Expected: > 100, Result: 99"
instead of:
"Expected: true, Result: false"
which could virtually mean anything (even null, undefined, string, array, you name it)

* Also fixed issue in jquery.colorUtil.js

tests/qunit/suites/resources/jquery/jquery.autoEllipsis.js
tests/qunit/suites/resources/jquery/jquery.colorUtil.js
tests/qunit/suites/resources/mediawiki/mediawiki.js

index 8a25439..e7bf032 100644 (file)
@@ -23,6 +23,23 @@ function findDivergenceIndex( a, b ) {
 test( 'Position right', function() {
        expect(3);
 
+       /**
+        * Extra QUnit assertions
+        * Needed in order to include the expected and actual values in the output.
+        * This way we end up with:
+        * "Expected: > 100, Result: 99"
+        * instead of:
+        * "Expected: true, Result: false"
+        */
+       // Expect numerical value less than or equal to X
+       var ltOrEq = function( actual, expected, message ) {
+               QUnit.push( actual <= expected, actual, 'less than or equal to ' + expected, message );
+       };
+       // Expect numerical value greater than X
+       var gt = function( actual, expected, message ) {
+               QUnit.push( actual > expected, actual, 'greater than ' + expected, message );
+       };
+
        // We need this thing to be visible, so append it to the DOM
        var origText = 'This is a really long random string and there is no way it fits in 100 pixels.';
        var $wrapper = createWrappedDiv( origText );
@@ -35,7 +52,7 @@ test( 'Position right', function() {
 
        // Check that the text fits by turning on word wrapping
        $span.css( 'whiteSpace', 'nowrap' );
-       strictEqual( $span.width() <= $span.parent().width(), true, "Text fits (span's width is no larger than its parent's width)" );
+       ltOrEq( $span.width(), $span.parent().width(), "Text fits (span's width is no larger than its parent's width)" );
 
        // Add one character using scary black magic
        var spanText = $span.text();
@@ -44,7 +61,7 @@ test( 'Position right', function() {
 
        // Put this text in the span and verify it doesn't fit
        $span.text( spanText );
-       strictEqual( $span.width() > $span.parent().width(), true, 'Fit is maximal (adding one character makes it not fit any more)' );
+       gt( $span.width(), $span.parent().width(), 'Fit is maximal (adding one character makes it not fit any more)' );
 
        // Clean up
        $wrapper.remove();
index 01965a2..93f12b8 100644 (file)
@@ -28,7 +28,7 @@ test( 'getRGB', function() {
        strictEqual( $.colorUtil.getRGB( 'rgba(0,0,0,0)' ), undefined, 'Zero rgba without whitespace' );
 
        deepEqual( $.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (lightGreen)' );
-       deepEqual( $.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (transparent)' );
+       deepEqual( $.colorUtil.getRGB( 'transparent' ), [255, 255, 255], 'Color names (transparent)' );
        strictEqual( $.colorUtil.getRGB( 'mediaWiki' ), undefined, 'Inexisting color name' );
 });
 
index 8b65659..d74f89e 100644 (file)
@@ -16,6 +16,7 @@ test( '-- Initial check', function() {
 
 test( 'mw.Map', function() {
        expect(15);
+
        ok( mw.Map, 'mw.Map defined' );
 
        var     conf = new mw.Map(),