mediawiki.api: Make qunit failure easier to debug
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 9 Feb 2017 20:10:58 +0000 (20:10 +0000)
committerTimo Tijhof <krinklemail@gmail.com>
Thu, 9 Feb 2017 20:10:58 +0000 (20:10 +0000)
Avoid use of assert.ok() when there is clearly a comparison being made.
Previously the result of the comparison was implicit in match() returning
an array with a match instead of null.

Change this to instead extract the value and let QUnit see the comparison.
In case of a failure, the actual and expected values will now be reported.

Change-Id: Ieaea090469efba24f6f5bf44f5c8e238b017275f

tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js

index 6fcdbb3..3f5e8c3 100644 (file)
                return sequence( bodies );
        }
 
+       // Utility to make inline use with an assert easier
+       function match( text, pattern ) {
+               var m = text.match( pattern );
+               return m && m[ 1 ] || null;
+       }
+
        QUnit.test( 'get()', function ( assert ) {
                var api = new mw.Api();
 
@@ -93,7 +99,7 @@
                var api = new mw.Api();
 
                this.server.respond( function ( request ) {
-                       assert.ok( request.url.match( /test=foo%7Cbar%7Cbaz/ ), 'Pipe-separated value was submitted' );
+                       assert.equal( match( request.url, /test=([^&]+)/ ), 'foo%7Cbar%7Cbaz', 'Pipe-separated value was submitted' );
                        request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
                } );
 
                var api = new mw.Api();
 
                this.server.respond( function ( request ) {
-                       assert.ok( request.url.match( /test=Foo%7CBar/ ), 'Pipe-separated value was submitted' );
+                       assert.equal( match( request.url, /test=([^&]+)/ ), 'Foo%7CBar', 'Pipe-separated value was submitted' );
                        request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
                } );
 
                var api = new mw.Api();
 
                this.server.respond( function ( request ) {
-                       assert.ok( request.url.match( /test=true%7Cfalse%7C%7C%7C0%7C1%2E2/ ), 'Pipe-separated value was submitted: ' + request.url );
+                       assert.equal( match( request.url, /test=([^&]+)/ ), 'true%7Cfalse%7C%7C%7C0%7C1%2E2', 'Pipe-separated value was submitted' );
                        request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
                } );