diff --git a/qunit/qunit-tests.ts b/qunit/qunit-tests.ts index 20285e8022..5c56a428b9 100644 --- a/qunit/qunit-tests.ts +++ b/qunit/qunit-tests.ts @@ -1636,4 +1636,35 @@ function testAfterDone() { ok(i); } }); -} \ No newline at end of file +} + +// 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 = 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); + } +}); \ No newline at end of file diff --git a/qunit/qunit.d.ts b/qunit/qunit.d.ts index a176712d75..a2a87e2860 100644 --- a/qunit/qunit.d.ts +++ b/qunit/qunit.d.ts @@ -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.