From: Timo Tijhof Date: Tue, 7 Aug 2012 23:54:34 +0000 (+0200) Subject: (bug 38987) mediawiki.api.parse.test: Fix test breakage X-Git-Tag: 1.31.0-rc.0~22799^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=89688d6ce0a586a45ec6634fba306fdbba481127;p=lhc%2Fweb%2Fwiklou.git (bug 38987) mediawiki.api.parse.test: Fix test breakage The direct html comparison is not stable enough due to interference if Tidy. Working around by doing a dom comparison instead of raw html. Change-Id: I62e39e0b05e3f9b5f78e2ac28a6f3ca0b608d152 --- diff --git a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js index f33edb02db..3d3f630f60 100644 --- a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js +++ b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js @@ -1,17 +1,25 @@ QUnit.module( 'mediawiki.api.parse', QUnit.newMwEnvironment() ); -QUnit.asyncTest( 'Simple', function ( assert ) { +QUnit.asyncTest( 'Hello world', function ( assert ) { var api; - QUnit.expect( 1 ); + QUnit.expect( 6 ); api = new mw.Api(); api.parse( "'''Hello world'''" ) .done( function ( html ) { - // Html also contains "NewPP report", so only check the first part - assert.equal( html.substr( 0, 25 ), '

Hello world

', - 'Wikitext to html parsing works.' - ); + // Parse into a document fragment instead of comparing HTML, due to + // presence of Tidy influencing whitespace. + // Html also contains "NewPP report" comment. + var $res = $( '
' ).html( html ).children(), + res = $res.get( 0 ); + assert.equal( $res.length, 1, 'Response contains 1 element' ); + assert.equal( res.nodeName.toLowerCase(), 'p', 'Response is a paragraph' ); + assert.equal( $res.children().length, 1, 'Response has 1 child element' ); + assert.equal( $res.children().get( 0 ).nodeName.toLowerCase(), 'b', 'Child element is a bold tag' ); + // Trim since Tidy may or may not mess with the spacing here + assert.equal( $.trim( $res.text() ), 'Hello world', 'Response contains given text' ); + assert.equal( $res.find( 'b' ).text(), 'Hello world', 'Bold tag wraps the entire, same, text' ); QUnit.start(); });