Bones/node_modules/reflect-metadata/test/reflect/reflect-metadata.ts

38 lines
1.3 KiB
TypeScript
Raw Normal View History

2017-05-17 13:45:25 -04:00
// Reflect.metadata ( metadataKey, metadataValue )
// - https://github.com/jonathandturner/decorators/blob/master/specs/metadata.md#reflectmetadata--metadatakey-metadatavalue-
import "../../Reflect";
import * as assert from "assert";
export function ReflectMetadataReturnsDecoratorFunction() {
let result = Reflect.metadata("key", "value");
assert.equal(typeof result, "function");
}
export function ReflectMetadataDecoratorThrowsWithInvalidTargetWithTargetKey() {
let decorator = Reflect.metadata("key", "value");
assert.throws(() => decorator(undefined, "name"), TypeError);
}
export function ReflectMetadataDecoratorThrowsWithInvalidTargetWithoutTargetKey() {
let decorator = Reflect.metadata("key", "value");
assert.throws(() => decorator({}, undefined), TypeError);
}
export function ReflectMetadataDecoratorSetsMetadataOnTargetWithoutTargetKey() {
let decorator = Reflect.metadata("key", "value");
let target = function () {}
decorator(target);
let result = Reflect.hasOwnMetadata("key", target, undefined);
assert.equal(result, true);
}
export function ReflectMetadataDecoratorSetsMetadataOnTargetWithTargetKey() {
let decorator = Reflect.metadata("key", "value");
let target = {}
decorator(target, "name");
let result = Reflect.hasOwnMetadata("key", target, "name");
assert.equal(result, true);
}