3 QUnit
.module( 'Templates', {
6 registerPartial
: $.noop
,
8 return 'abc default compiler';
11 // Register some template compiler languages
12 mw
.template
.registerCompiler( 'abc', abcCompiler
);
13 mw
.template
.registerCompiler( 'xyz', {
14 registerPartial
: $.noop
,
15 compile: function () {
16 return 'xyz compiler';
20 // register some templates
22 'test.mediawiki.templates': {
23 'test_templates_foo.xyz': 'goodbye',
24 'test_templates_foo.abc': 'thankyou'
30 QUnit
.test( 'Template, getCompiler - default case', 4, function ( assert
) {
31 assert
.throws( function () {
32 mw
.template
.add( 'module', 'test_templates_foo', 'hello' );
33 }, 'When no prefix throw exception.' );
34 assert
.throws( function () {
35 mw
.template
.compile( '{{foo}}', 'rainbow' );
36 }, 'Unknown compiler names throw exceptions.' );
37 assert
.strictEqual( mw
.template
.get( 'test.mediawiki.templates', 'test_templates_foo.xyz' ), 'xyz compiler' );
38 assert
.strictEqual( mw
.template
.get( 'test.mediawiki.templates', 'test_templates_foo.abc' ), 'abc default compiler' );
41 QUnit
.test( 'Template, get module that is not loaded.', 2, function ( assert
) {
42 assert
.throws( function () {
43 mw
.template
.get( 'this.should.not.exist', 'hello' );
44 }, 'When bad module name given throw error.' );
46 assert
.throws( function () {
47 mw
.template
.get( 'mediawiki.templates', 'hello' );
48 }, 'The template hello should not exist in the mediawiki.templates module and should throw an exception.' );
51 }( mediaWiki
, jQuery
) );