Adds extend to QUnit typings (#9322)

Note that the second parameter (mixin) of this method is documented on
the website as being of type string, but both the qunit source code and
examples on the same documentation page tell us it's actually of type
any.
This commit is contained in:
Jeroen
2016-05-15 02:28:09 +09:00
committed by Masahiro Wakame
parent 2c530936fe
commit 933f68a564
2 changed files with 44 additions and 1 deletions
+32 -1
View File
@@ -1636,4 +1636,35 @@ function testAfterDone() {
ok(i);
}
});
}
}
// Example QUnit.extend call taken from: http://api.qunitjs.com/QUnit.extend/
QUnit.test( "QUnit.extend", function( assert ) {
var base = {
a: 1,
b: 2,
z: 3
};
QUnit.extend( base, {
b: 2.5,
c: 3,
z: undefined
} );
// Change from documentation example to satisfy tsc:
var newBase = <any> base;
assert.equal( newBase.a, 1, "Unspecified values are not modified" );
assert.equal( newBase.b, 2.5, "Existing values are updated" );
assert.equal( newBase.c, 3, "New values are defined" );
assert.ok( !( "z" in newBase ), "Values specified as `undefined` are removed" );
});
// Example QUnit.extend usage taken from: http://stackoverflow.com/a/33439774/419956
QUnit.extend(QUnit.assert, {
matches: function (actual, regex, message) {
var success = !!regex && !!actual && (new RegExp(regex)).test(actual);
var expected = "String matching /" + regex.toString() + "/";
this.push(success, actual, expected, message);
}
});
+12
View File
@@ -469,6 +469,18 @@ interface QUnitStatic extends QUnitAssert {
* @depricated since version 1.16
*/
expect(amount: number): any;
/**
* Copy the properties defined by the mixin object into the target object.
*
* This method will modify the target object to contain the "own" properties defined
* by the mixin. If the mixin object specifies the value of any attribute as undefined,
* this property will instead be removed from the target object.
*
* @param target An object whose properties are to be modified
* @param mixin An object describing which properties should be modified
*/
extend(target: any, mixin: any): any;
/**
* Group related tests under a single label.