Bones/node_modules/reflect-metadata/test/reflect/reflect-getmetadata.ts
SOUTHERNCO\x2mjbyrn 7efe7605b8 Template Upload
2017-05-17 13:45:25 -04:00

52 lines
1.8 KiB
TypeScript

// Reflect.getMetadata ( metadataKey, target [, propertyKey] )
// - https://github.com/jonathandturner/decorators/blob/master/specs/metadata.md#reflectgetmetadata--metadatakey-target--propertykey-
import "../../Reflect";
import * as assert from "assert";
export function ReflectGetMetadataInvalidTarget() {
assert.throws(() => Reflect.getMetadata("key", undefined, undefined), TypeError);
}
export function ReflectGetMetadataWithoutTargetKeyWhenNotDefined() {
let obj = {};
let result = Reflect.getMetadata("key", obj, undefined);
assert.equal(result, undefined);
}
export function ReflectGetMetadataWithoutTargetKeyWhenDefined() {
let obj = {};
Reflect.defineMetadata("key", "value", obj, undefined);
let result = Reflect.getMetadata("key", obj, undefined);
assert.equal(result, "value");
}
export function ReflectGetMetadataWithoutTargetKeyWhenDefinedOnPrototype() {
let prototype = {};
let obj = Object.create(prototype);
Reflect.defineMetadata("key", "value", prototype, undefined);
let result = Reflect.getMetadata("key", obj, undefined);
assert.equal(result, "value");
}
export function ReflectGetMetadataWithTargetKeyWhenNotDefined() {
let obj = {};
let result = Reflect.getMetadata("key", obj, "name");
assert.equal(result, undefined);
}
export function ReflectGetMetadataWithTargetKeyWhenDefined() {
let obj = {};
Reflect.defineMetadata("key", "value", obj, "name");
let result = Reflect.getMetadata("key", obj, "name");
assert.equal(result, "value");
}
export function ReflectGetMetadataWithTargetKeyWhenDefinedOnPrototype() {
let prototype = {};
let obj = Object.create(prototype);
Reflect.defineMetadata("key", "value", prototype, "name");
let result = Reflect.getMetadata("key", obj, "name");
assert.equal(result, "value");
}