Skip to content

Commit

Permalink
test: add object metadata and property metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Velmisov committed Jul 20, 2020
1 parent 6bc6eb9 commit cc17c5d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion test/fixtures/add-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { ReflectIsObject } from '../../src/utils';

export function AddClassMetadata(
metadataKey: any, // eslint-disable-line
metadataValue: any, // eslint-disable-line
): ClassDecorator {
return Reflect.metadata(metadataKey, metadataValue);
return (constructor: Function): void => {
Reflect.defineMetadata(metadataKey, metadataValue, constructor);
Reflect.defineMetadata(
metadataKey,
metadataValue,
constructor.prototype,
'constructor',
);
};
}

export function AddPropertyMetadata(
Expand All @@ -12,5 +22,11 @@ export function AddPropertyMetadata(
return (target: Object, propertyKey: string | symbol): void => {
target[propertyKey] = target[propertyKey] || undefined;
Reflect.defineMetadata(metadataKey, metadataValue, target, propertyKey);
if (ReflectIsObject(target[propertyKey]))
Reflect.defineMetadata(
metadataKey,
metadataValue,
target[propertyKey],
);
};
}

0 comments on commit cc17c5d

Please sign in to comment.