From: Timo Tijhof Date: Thu, 9 Feb 2017 20:10:58 +0000 (+0000) Subject: mediawiki.api: Make qunit failure easier to debug X-Git-Tag: 1.31.0-rc.0~4113^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=commitdiff_plain;h=0267b4129f0979e158fee7e3e5ac140d5fc5969e;p=lhc%2Fweb%2Fwiklou.git mediawiki.api: Make qunit failure easier to debug 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 --- diff --git a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js index 6fcdbb33b5..3f5e8c32a0 100644 --- a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js +++ b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js @@ -24,6 +24,12 @@ 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' }, '[]' ); } ); @@ -104,7 +110,7 @@ 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' }, '[]' ); } ); @@ -115,7 +121,7 @@ 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' }, '[]' ); } );