QUnit.module( 'mediawiki.base/html', () => { QUnit.test( 'escape', ( assert ) => { assert.throws( () => { mw.html.escape(); }, TypeError, 'throw a TypeError if argument is not a string' ); assert.strictEqual( mw.html.escape( '' ), '<mw awesome="awesome" value='test' />', 'Escape special characters to html entities' ); } ); QUnit.test( 'element()', ( assert ) => { assert.strictEqual( mw.html.element(), '', 'return valid html even without arguments' ); } ); QUnit.test( 'element( tagName )', ( assert ) => { assert.strictEqual( mw.html.element( 'div' ), '
', 'DIV' ); } ); QUnit.test( 'element( tagName, attrs )', ( assert ) => { assert.strictEqual( mw.html.element( 'div', {} ), '
', 'DIV' ); assert.strictEqual( mw.html.element( 'div', { id: 'foobar' } ), '
', 'DIV with attribs' ); } ); QUnit.test( 'element( tagName, attrs, content )', ( assert ) => { assert.strictEqual( mw.html.element( 'div', {}, '' ), '
', 'DIV with empty attributes and content' ); assert.strictEqual( mw.html.element( 'p', {}, 12 ), '

12

', 'numbers as content cast to strings' ); assert.strictEqual( mw.html.element( 'p', { title: 12 }, '' ), '

', 'number as attribute value' ); assert.strictEqual( mw.html.element( 'div', {}, new mw.html.Raw( mw.html.element( 'img', { src: '<' } ) ) ), '
', 'unescaped content with mw.html.Raw' ); assert.strictEqual( mw.html.element( 'option', { selected: true }, 'Foo' ), '', 'boolean true attribute value' ); assert.strictEqual( mw.html.element( 'option', { value: 'foo', selected: false }, 'Foo' ), '', 'boolean false attribute value' ); assert.strictEqual( mw.html.element( 'div', null, 'a' ), '
a
', 'Skip attributes with null' ); assert.strictEqual( mw.html.element( 'a', { href: 'http://mediawiki.org/w/index.php?title=RL&action=history' }, 'a' ), 'a', 'Andhor tag with attributes and content' ); } ); } );