1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
QUnit.module( 'mediawiki.api', QUnit.newMwEnvironment() );
QUnit.asyncTest( 'Basic functionality', function ( assert ) {
var api, d1, d2, d3;
QUnit.expect( 3 );
api = new mw.Api();
d1 = api.get( {} )
.done( function ( data ) {
assert.deepEqual( data, [], 'If request succeeds without errors, resolve deferred' );
});
d2 = api.get({
action: 'doesntexist'
})
.fail( function ( errorCode, details ) {
assert.equal( errorCode, 'unknown_action', 'API error (e.g. "unknown_action") should reject the deferred' );
});
d3 = api.post( {} )
.done( function ( data ) {
assert.deepEqual( data, [], 'Simple POST request' );
});
// After all are completed, continue the test suite.
QUnit.whenPromisesComplete( d1, d2, d3 ).always( function () {
QUnit.start();
});
});
QUnit.asyncTest( 'Deprecated callback methods', function ( assert ) {
var api, d1, d2, d3;
QUnit.expect( 3 );
api = new mw.Api();
d1 = api.get( {}, function () {
assert.ok( true, 'Function argument treated as success callback.' );
});
d2 = api.get( {}, {
ok: function ( data ) {
assert.ok( true, '"ok" property treated as success callback.' );
}
});
d3 = api.get({
action: 'doesntexist'
}, {
err: function ( data ) {
assert.ok( true, '"err" property treated as error callback.' );
}
});
QUnit.whenPromisesComplete( d1, d2, d3 ).always( function () {
QUnit.start();
});
});
|