2 QUnit
.module( 'mediawiki.base' );
4 QUnit
.test( 'mw.hook - basic', function ( assert
) {
6 mw
.hook( 'test.hook.basic' ).add( function () {
10 mw
.hook( 'test.hook.basic' ).fire();
11 assert
.deepEqual( q
, [ 'basic' ], 'Callback' );
14 QUnit
.test( 'mw.hook - name', function ( assert
) {
16 mw
.hook( 'hasOwnProperty' ).add( function () {
17 q
.push( 'prototype' );
20 mw
.hook( 'hasOwnProperty' ).fire();
21 assert
.deepEqual( q
, [ 'prototype' ], 'Callback' );
24 QUnit
.test( 'mw.hook - data', function ( assert
) {
27 mw
.hook( 'test.hook.data' ).add( function ( data1
, data2
) {
30 mw
.hook( 'test.hook.data' ).fire( 'example', [ 'two' ] );
37 'Data containing a string and an array'
41 QUnit
.test( 'mw.hook - chainable', function ( assert
) {
42 var hook
, add
, fire
, q
= [];
44 hook
= mw
.hook( 'test.hook.chainable' );
45 assert
.strictEqual( hook
.add(), hook
, 'hook.add is chainable' );
46 assert
.strictEqual( hook
.remove(), hook
, 'hook.remove is chainable' );
47 assert
.strictEqual( hook
.fire(), hook
, 'hook.fire is chainable' );
49 hook
= mw
.hook( 'test.hook.detach' );
52 add( function ( x
, y
) {
56 assert
.deepEqual( q
, [ 'x', 'y' ], 'Contextless firing with data' );
59 QUnit
.test( 'mw.hook - memory before', function ( assert
) {
63 mw
.hook( 'test.hook.fireBefore' ).fire().add( function () {
66 assert
.deepEqual( q
, [ 'X' ], 'Remember previous firing for newly added handler' );
69 mw
.hook( 'test.hook.fireTwiceBefore' ).fire( 'Y1' ).fire( 'Y2' ).add( function ( data
) {
72 assert
.deepEqual( q
, [ 'Y2' ], 'Remember only the most recent firing' );
75 QUnit
.test( 'mw.hook - memory before and after', function ( assert
) {
77 mw
.hook( 'test.hook.many' )
78 .add( function ( chr
) {
81 .fire( 'x' ).fire( 'y' ).fire( 'z' )
82 .add( function ( chr
) {
86 assert
.deepEqual( q1
, [ 'x', 'y', 'z' ], 'Multiple fires after callback addition' );
87 assert
.deepEqual( q2
, [ 'z' ], 'Last fire applied to new handler' );
90 QUnit
.test( 'mw.hook - data variadic', function ( assert
) {
92 function callback( chr
) {
96 mw
.hook( 'test.hook.variadic' )
118 [ 'x', 'x', 'x', 'x', 'y', 'z' ],
119 '"add" and "remove" support variadic arguments. ' +
120 '"add" does not filter unique. ' +
121 '"remove" removes all equal by reference. ' +
122 '"remove" is silent if the function is not found'
126 QUnit
.test( 'RLQ.push', function ( assert
) {
129 done
= assert
.async();
130 mw
.loader
.testCallback = function () {
132 delete mw
.loader
.testCallback
;
134 mw
.loader
.implement( 'test.rlq-push', [ QUnit
.fixurl( mw
.config
.get( 'wgScriptPath' ) + '/tests/qunit/data/mwLoaderTestCallback.js' ) ] );
136 RLQ
.push( [ 'test.rlq-push', function () {
137 assert
.strictEqual( loaded
, 1, 'Load the required module' );