build(aio): ensure the correct decorator properties are merged (#24289)
Previously only the `description` and `usageNotes` were being copied over from the call-member of the decorator interface. Important properties such as `shortDescription` were missed. These are now added and the code has been refactored to make it simpler and clearer to update which properties get copied as the requirements change. PR Close #24289
This commit is contained in:

committed by
Victor Berchet

parent
19deca159b
commit
0ae8ea254a
@ -96,5 +96,19 @@ module.exports = {
|
||||
attrMap[key] === false ? '' :
|
||||
attrMap[key] === true ? ` ${key}` :
|
||||
` ${key}="${attrMap[key].replace(/"/g, '"')}"`).join('');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Merge the specified properties from the source to the target document
|
||||
* @param {Document} target The document to receive the properties from the source
|
||||
* @param {Document} source The document from which to get the properties to merge
|
||||
* @param {string[]} properties A collection of the names of the properties to merge
|
||||
*/
|
||||
mergeProperties(target, source, properties) {
|
||||
properties.forEach(property => {
|
||||
if (source.hasOwnProperty(property)) {
|
||||
target[property] = source[property];
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
const { mapObject, parseAttributes, renderAttributes } = require('./utils');
|
||||
const { mergeProperties, mapObject, parseAttributes, renderAttributes } = require('./utils');
|
||||
|
||||
describe('utils', () => {
|
||||
describe('mapObject', () => {
|
||||
@ -96,4 +96,34 @@ describe('utils', () => {
|
||||
expect(renderAttributes({ })).toEqual('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('mergeProperties', () => {
|
||||
it('should write specified properties from the source to the target', () => {
|
||||
const source = { a: 1, b: 2, c: 3 };
|
||||
const target = { };
|
||||
mergeProperties(target, source, ['a', 'b']);
|
||||
expect(target).toEqual({ a: 1, b: 2 });
|
||||
});
|
||||
|
||||
it('should not overwrite target properties that are not specified', () => {
|
||||
const source = { a: 1, b: 2, c: 3 };
|
||||
const target = { b: 10 };
|
||||
mergeProperties(target, source, ['a']);
|
||||
expect(target).toEqual({ a: 1, b: 10 });
|
||||
});
|
||||
|
||||
it('should not overwrite target properties that are specified but do not exist in the source', () => {
|
||||
const source = { a: 1 };
|
||||
const target = { b: 10 };
|
||||
mergeProperties(target, source, ['a', 'b']);
|
||||
expect(target).toEqual({ a: 1, b: 10 });
|
||||
});
|
||||
|
||||
it('should overwrite target properties even if they are `undefined` in the source', () => {
|
||||
const source = { a: undefined };
|
||||
const target = { a: 10 };
|
||||
mergeProperties(target, source, ['a']);
|
||||
expect(target).toEqual({ a: undefined });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user