2 QUnit
.module( 'mediawiki.api.parse', QUnit
.newMwEnvironment( {
4 this.server
= this.sandbox
.useFakeServer();
5 this.server
.respondImmediately
= true;
9 QUnit
.test( '.parse( string )', function ( assert
) {
10 this.server
.respondWith( /action=parse.*&text='''Hello(\+|%20)world'''/, [ 200,
11 { 'Content-Type': 'application/json' },
12 '{ "parse": { "text": "<p><b>Hello world</b></p>" } }'
15 return new mw
.Api().parse( '\'\'\'Hello world\'\'\'' ).done( function ( html
) {
16 assert
.strictEqual( html
, '<p><b>Hello world</b></p>', 'Parse wikitext by string' );
20 QUnit
.test( '.parse( Object.toString )', function ( assert
) {
21 this.server
.respondWith( /action=parse.*&text='''Hello(\+|%20)world'''/, [ 200,
22 { 'Content-Type': 'application/json' },
23 '{ "parse": { "text": "<p><b>Hello world</b></p>" } }'
26 return new mw
.Api().parse( {
27 toString: function () {
28 return '\'\'\'Hello world\'\'\'';
30 } ).done( function ( html
) {
31 assert
.strictEqual( html
, '<p><b>Hello world</b></p>', 'Parse wikitext by toString object' );
35 QUnit
.test( '.parse( mw.Title )', function ( assert
) {
36 this.server
.respondWith( /action=parse.*&page=Earth/, [ 200,
37 { 'Content-Type': 'application/json' },
38 '{ "parse": { "text": "<p><b>Earth</b> is a planet.</p>" } }'
41 return new mw
.Api().parse( new mw
.Title( 'Earth' ) ).done( function ( html
) {
42 assert
.strictEqual( html
, '<p><b>Earth</b> is a planet.</p>', 'Parse page by Title object' );