qunit: Add SinonJS utility
To be used in mediawiki.api tests and elsewhere.
For now they are opt-in and disabled by default,
individual tests can enable fake timers, servers and/or
xhrs by calling this.sandbox to access the dedicated
sinon sandbox for that test.
Clock example:
QUnit.test( 'example', function ( assert ) {
var clock = this.sandbox.useFakeTimers();
setTimeout( function () {
assert.ok( true, 'test' );
} );
clock.tick(1);
} );
Server example:
QUnit.test( 'example', function ( assert ) {
this.server = this.sandbox.useFakeServer();
new mw.Api().getToken( 'foo' ).done( function ( token ) {
assert.equal( token, '
0123abc', 'Token' );
} );
// assert.equal( this.server.requests.length, 1, 'Requests' );
this.server.respond( function ( request ) {
request.respond( 200, { 'Content-Type': 'application/json' },
'{ "tokens": { "testactiontoken": "
0123abc" } }'
);
} );
} );
Change-Id: I789fb71903f26dbbfe781f010dc5cd3756759943