On this page
QUnit.extend()
version added: 1.0.0
deprecated: 2.12.0
Description
QUnit.extend( target, mixin )
Copy the properties defined by a mixin object into a target object.
This method is deprecated and it’s recommended to use Object.assign() instead.
| name | description |
|---|---|
target |
An object whose properties are to be modified |
mixin |
An object describing which properties should be modified |
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.
Examples
Use QUnit.extend to merge two objects.
QUnit.test('QUnit.extend', assert => {
const base = {
a: 1,
b: 2,
z: 3
};
QUnit.extend(base, {
b: 2.5,
c: 3,
z: undefined
});
assert.strictEqual(base.a, 1, 'Unspecified values are not modified');
assert.strictEqual(base.b, 2.5, 'Existing values are updated');
assert.strictEqual(base.c, 3, 'New values are defined');
assert.false('z' in base, 'Values specified as `undefined` are removed');
});
© OpenJS Foundation and contributors.
Licensed under the MIT license.
https://api.qunitjs.com/extension/QUnit.extend